在多个清单主机组上运行ansible任务

问题描述 投票:1回答:1

我正在多个库存组上运行相同的任务,例如:

[big_group]
greenhat
localhost
redhat
linux

[small_group]
localhost

[redhat_group]
redhat

从我的剧本中,我需要同时在[small_group][redhat_group]]上运行任务

我的任务如下

  - name: Disable HTTPS service from firewalld
    firewalld:
      service: https
      permanent: false
      state: disabled
      zone: public
      immediate: true
    when: inventory_hostname in groups['small_group']
    when: inventory_hostname in groups['redhat_group']

收到警告为

 [WARNING]: While constructing a mapping from firewall.yml, line 6, column 5, found a duplicate dict key (when). Using last defined value only.

Playbook结果:

TASK [Disable HTTPS service from firewalld] **************************************************************************************************************************************************
skipping: [localhost]
skipping: [redhat]

如何在“以下时间中指定多个组:组[]中的库存主机名]]

谢谢

我正在多个清单组上运行相同的任务,例如:[big_group] greenhat localhost redhat linux [small_group] localhost [redhat_group] redhat从我的剧本中,我需要运行一个...

ansible ansible-inventory
1个回答
1
投票

您在一个任务中不能有多个when子句。对于您的情况,您只需要加入两个组(+)并删除多个条目(如果有)(使用unique filter,以便将来更改库存)。

unique
© www.soinside.com 2019 - 2024. All rights reserved.