ansible 条件判断

ansible 收集远程主机的一些信息:

ansible all -m setup 

应用到playbook中:

---

- name: ansible playbook
  hosts: all
  remote_user: root
  become: yes
  vars:
	user_name: 'test'
  var_files:
  
  tasks:
	- name: Debian
	  debug:
		msg: 'Debian'
	  when:
		ansible_os_family == 'Debian'
	  tags:
		- test

测试:

ansible-playbook play.yml -t test