目标是限制主持人的团队,在游戏中运行一个剧本。下面的代码并不限制组对集群进行分组,有时在localhost上运行下面的剧本
- hosts: all:!localhost
gather_facts: no
tasks:
... 库存档案如下:
[localhost]
127.0.0.1 ansible_connection=local
[cluster]
ip1
ip2
ip3然而,尝试过的- hosts: cluster有时仍然在localhost上运行。
可以选择通过cli限制这些组
ansible-playbook playbooks/PLAYBOOK_NAME.yml --limit 'all:!localhost'我的目标是限制组一个游戏是运行上从游戏手册的源代码。
发布于 2019-03-13 08:30:27
- name: Ensure dir exists
file:
path: example/path
state: directory
owner: user
group: group
mode: 0755
when: inventory_hostname in groups['cluster']以下是诀窍。它只在您想要的组上运行任务。
when: inventory_hostname in groups['cluster']发布于 2019-03-13 08:48:22
然后在所需的主机组上运行。
- hosts: cluster,cluster1,cluster2
gather_facts: no
tasks:
... 或者在目录中,您可以将主机组按以下几个类别分组:
[cluster]
ip1
ip2
ip3
[clusters:children]
cluster
cluster1 然后在集群组上运行游戏手册。
https://stackoverflow.com/questions/55127815
复制相似问题