{{ cat }}'s docs

1.3.11: playbook-when distribution version/release


0. 需求

有时候使用when语句,需要根据系统版本的信息进行判断


1. 需要以下条件和变量

  • 条件: gather_facts: yes
  • 变量:
    • ansible_distribution - "Ubuntu","CentOS","RedHat","Debian"
    • ansible_distribution_release - "lucid","Final","precise","wheezy"
    • ansible_distribution_version - "10.04","7","6.4"

2. 实例演示

# 筛选出centos 6.4
when: ansible_distribution == 'CentOS' and ansible_distribution_version == '6.4'

# 筛选出centos 5 6 7
when: ansible_os_family == "Centos" and ansible_distribution_version|int >= 5