ansible when条件语句用法

ansible when条件语句用法

参考

基本用法

- hosts: all
  tasks:
    - include: Ubuntu.yml
      when: ansible_os_family == "Ubuntu"
    
    - include: RHEL.yml
      when: ansible_os_family == "RedHat"

语法

When: condition1 and/or condition2

举例

when:
  ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and
  (ansible_distribution_version|version_compare('7', '<') or
  ansible_distribution_version|version_compare('8', '>='))
  or
  ansible_distribution == 'Fedora'
  or
  ansible_distribution == 'Ubuntu' and
  ansible_distribution_version|version_compare('15.04', '>=')

and 还有一种写法,这种写法更简洁

when:
  - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
  - ansible_distribution_version|version_compare('15.04', '>=')
上一篇:寻找峰值


下一篇:山东大学软件专业大一作业(上学期)作业七