Ansible任务将在" server_1"以外的主机上运行或" server_2"

时间:2017-10-16 13:15:07

标签: ansible conditional

我希望能够仅在不匹配" server_1"的主机上运行ansible任务。或" server_2"。

半伪代码:

- name: Set localtime
  file: src=/usr/share/zoneinfo/UTC
        dest=/etc/localtime
        state=link
  when: only when hostname is NOT "server_1" or "server_2"

2 个答案:

答案 0 :(得分:2)

比较主机名:

when: ansible_hostname not in ['server_1', 'server_2']

比较库存别名:

when: inventory_hostname not in ['server_1', 'server_2']

答案 1 :(得分:0)

你可以试试这个:

- name: Set localtime
  file: src=/usr/share/zoneinfo/UTC
        dest=/etc/localtime
        state=link
  when: ansible_hostname not in [server_1', 'server_2']