IT袋

当前位置:主页 > 经验教程 > 系统教程 >

Ansible的条件判断介绍和使用方式详解

Ansible的条件判断介绍和使用方式详解!(6)

时间:2023-09-17 20:48:10 来源:IT袋 作者:苏晓敏
导读:Ansible的条件判断介绍和使用方式详解,- shell: /usr/bin/billybass --mode="take me to the river"register: bass_result# 该条task执行以后,bass_result.rc的值不为2时,才会返回changed状态changed_when: "bass_result.rc != 2"#

Ansible的条件判断介绍和使用方式详解

- shell: /usr/bin/billybass --mode="take me to the river"
register: bass_result
# 该条task执行以后,bass_result.rc的值不为2时,才会返回changed状态
changed_when: "bass_result.rc != 2"
# this will never report 'changed' status
- shell: wall 'beep'
  # 当changed_when为false时,该条task在执行以后,永远不会返回changed状态
  changed_when: False

循环语句中使用条件语句

  1. 只打印大于 10 的值
tasks:
    - command: echo {{ item }}
      loop: [ 0, 2, 4, 6, 8, 10, 100, 130, 150 ]
      when: item > 10
  1. 确保将mariadb-server安装到根分区且根分区的可用空间要大于200M
- name: install nginx if enough space on root
  yum: 
    name: nginx
    state;latest
  loop: "{{ ansible_mounts }}"
  when: item.mount == "/" and item.size_available > 200000000

以上就是大部分的判断方法,可能很多在职业生涯中都用不上。

上述就是Ansible的条件判断介绍和使用方式详解!的经验介绍,您知道和解决您袋问题了吗?

相关阅读