美文网首页
ansible条件判断

ansible条件判断

作者: 释惑的心 | 来源:发表于2020-04-01 09:54 被阅读0次

    when


    ```

    [root@localhost ~]#vim test.yml

    ---

    - hosts: B

      remote_user: root

      tasks:

      - debug: msg="system release is centos" #“”不能少

        when: ansible_distribution == "CentOS" #==两端加空格, "CentOS"引号不能少。在when中变量名不用加{{}}

    [root@localhost ~]#vim test.yml

    ---

    - hosts: B

      remote_user: root

      tasks:

      - debug: msg={{item}}

        with_items: [1,2,3]

        when: item > 2

    运算比较符:

    ==

    !=

    >

    <

    >=

    <=

    and

    or

    not

    ()

    ---

    - hosts: B

      remote_user: root

      tasks:

      - debug:

          msg: "System release is centos6 or centos7"

        when: ansible_distribution == "CentOS" and (ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7")

    ```

    相关文章

      网友评论

          本文标题:ansible条件判断

          本文链接:https://www.haomeiwen.com/subject/fihouhtx.html