我希望能够仅在不匹配" 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"
答案 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']