目前ansible的全部conditionals方式都是使用when進行判斷,when的值是一個條件表達式,若是判斷成立這個task就執行某個操做,不成立則不執行或跳過python
hosts: test
tasks:shell
name: Host localhost run this task
debug: msg="{{ ansible_default_ipv4.address }}"
when: ansible_default_ipv4.address == "172.19.95.175"ide
name: memtotal_mb < 1000M and ansible_processor_cores == 1 run this task
debug: msg="{{ ansible-fqdn }}"
when: ansible_memtotal_mb < 1000 and ansible_processor_cores == 1this
name: all host run this task
shell: hostname
register: infodebug
name: Hostname is python machie run this task
debug: msg="{{ ansible_fqdn }}"
when: info['stdout'] == "cxiong"blog
執行結果:
第4個若是不跳過:
ok: [192.168.1.1] => {
"msg": "cxiong"
}ip