判断语句 之 比较运算
| 比较符 | 释义 |
|---|---|
| == | 等于 |
| != | 不等 |
| < | 小于 |
| <= | 小于等于 |
| > | 大于 |
| >= | 大于等于 |
示例一:
需要注意 when 使用变量时不需要 {{}}
- hosts: all
tasks:
- name: debug
debug:
msg: 我的操作系统是红帽系列
when: ansible_os_family == "RedHat"
- name: debug
debug:
msg: 我的操作系统是debian系列
when: ansible_os_family == "DeBian"
示例二:
等同于:
for i in 0,1,2:
if i>1:
print(i)
- hosts: all
tasks:
- name: debug
debug:
msg: "{{ item }}"
with_items:
- 0
- 1
- 2
when: item >1
浙公网安备 33010602011771号