判断语句 之 逻辑运算
逻辑运算 | 释义 |
---|---|
and | 逻辑与 |
or | 逻辑或 |
not | 逻辑取反 |
示例一:
等同于:
if ansible_distribution == "CentOS" and ansible_distribution_major_version == "7":
print("我是centos7")
- hosts: all
tasks:
- name: debug
debug:
msg: "我是centos7"
when:
- ansible_distribution == "CentOS"
- ansible_distribution_major_version == "7"
示例二:
not 取反
- hosts: all
tasks:
- name: debug
debug:
msg: "我不是centos6"
when:
- ansible_distribution == "CentOS"
- not ansible_distribution_major_version == "6"