Ansible playbook条件判断


vim /etc/ansible/when.yml

---

- hosts: testhosts

  user: root

  gather_facts: True

  tasks:

    - name: use when

      shell: touch /tmp/when.txt

      when: facter_ipaddress == "192.168.11.30"   #条件判断


执行命令: ansible-playbook when.yml

说明:gather_facts: True打开会收集客户端的相关信息,判断facter_ipaddress来决定是否执行。

gather_facts: True用的是setup模块来收集信息的。ansible client.wyp.com -m setup


这个判断,通常用在发行版不同时,判断来使用一些有差异的命令。