码迷,mamicode.com
首页 > 其他好文 > 详细

ansible when条件语句用法

时间:2021-02-27 13:41:18      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:distrib   blank   mil   hat   ansi   cond   写法   参考   举例   

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‘, ‘>=‘)

ansible when条件语句用法

标签:distrib   blank   mil   hat   ansi   cond   写法   参考   举例   

原文地址:https://www.cnblogs.com/hiyang/p/14455143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!