when
```
[root@localhost ~]#vim test.yml
---
- hosts: B
remote_user: root
tasks:
- debug: msg="system release is centos" #“”不能少
when: ansible_distribution == "CentOS" #==两端加空格, "CentOS"引号不能少。在when中变量名不用加{{}}
[root@localhost ~]#vim test.yml
---
- hosts: B
remote_user: root
tasks:
- debug: msg={{item}}
with_items: [1,2,3]
when: item > 2
运算比较符:
==
!=
>
<
>=
<=
and
or
not
()
---
- hosts: B
remote_user: root
tasks:
- debug:
msg: "System release is centos6 or centos7"
when: ansible_distribution == "CentOS" and (ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7")
```
网友评论