• 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', '>=')
    
  • 相关阅读:
    进程
    并发编程
    操作系统的发展史
    __init__、__new__、__call__ 方法
    MongoDB文档操作
    MongoDB集合操作
    MongoDB数据库操作
    MongoDB连接
    MongoDB的文档存储结构
    MongoDB 概念
  • 原文地址:https://www.cnblogs.com/hiyang/p/14455143.html
Copyright © 2020-2023  润新知