ansible when
时间: 2023-11-17 22:04:24 浏览: 128
ansible
Ansible中的when语句用于在任务执行之前判断条件是否成立,只有条件成立时才会执行任务。when语句可以使用逻辑运算符and、or和not来组合多个条件,也可以使用括号来改变条件的优先级。以下是几个when语句的示例:
1. 逻辑与
```yaml
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
```
2. 逻辑或
```yaml
when: ansible_distribution == "RedHat" or ansible_distribution == "Fedora"
```
3. 组合使用
```yaml
when: ( ansible_distribution == "RedHat" and ansible_distribution_major_version == "7" ) or ( ansible_distribution == "Fedora" and ansible_distribution_major_version == "28" )
```
4. not运算符
```yaml
when: not ansible_distribution == "Ubuntu"
```
阅读全文