Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在多个资源清册主机组上运行ansible任务_Ansible_Ansible Inventory - Fatal编程技术网

在多个资源清册主机组上运行ansible任务

在多个资源清册主机组上运行ansible任务,ansible,ansible-inventory,Ansible,Ansible Inventory,我希望在多个库存组上运行相同的任务,例如: [big_group] greenhat localhost redhat linux [small_group] localhost [redhat_group] redhat 从我的剧本中,我需要在[small_group]和[redhat_group]上运行一个任务 我的任务如下 - name: Disable HTTPS service from firewalld firewalld: service: http

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

[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.
剧本结果:

TASK [Disable HTTPS service from firewalld] **************************************************************************************************************************************************
skipping: [localhost]
skipping: [redhat]
如何在when:inventory\u hostname in groups[]中指定多个组

谢谢

任务中不能有多个when子句。在您的情况下,您只需加入两个组+并删除多个条目(如果有),以便将来进行库存更改

时间:组中的资源清册主机名['small_group']+组['redhat_group'];唯一 同时,IMO还有一种更方便的方法,可以像在正常游戏中一样使用和利用

时间:在查找'inventory\u hostnames'、'small\u group:redhat\u group'中的inventory\u主机名 任务中不能有多个when子句。在您的情况下,您只需加入两个组+并删除多个条目(如果有),以便将来进行库存更改

时间:组中的资源清册主机名['small_group']+组['redhat_group'];唯一 同时,IMO还有一种更方便的方法,可以像在正常游戏中一样使用和利用

时间:在查找'inventory\u hostnames'、'small\u group:redhat\u group'中的inventory\u主机名