目前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