我有两组服务器A和B,我需要排除的服务器之一在A组中
我尝试了以下模式:
GroupA:!test-host,GroupB
这将导致“没有主机匹配”
我该怎么做?
答案 0 :(得分:0)
您可以
group_by
模块)创建新的分组group_vars / all.yaml:
mygroup: '{{ groups.foo|difference(groups.bar) }}'
播放:
hosts: '{{ mygroup }}'
或者,如果主机在特定组中,则可以终止该主机的播放。
- name: Stop doing this for bar
meta: end_host
when: "'bar' in group_names"
答案 1 :(得分:0)
库存
shell> cat hosts
[groupA]
test1
test2
test-host
[groupB]
test3
test4
和剧本
shell> cat pb.yml
- hosts: groupB:groupA:!test-host
tasks:
- debug:
var: ansible_play_hosts_all
run_once: true
给予
shell> ansible-playbook -i hosts pb.yml
ok: [test3] => {
"ansible_play_hosts_all": [
"test3",
"test4",
"test1",
"test2"
]
}
- hosts: all
时,该命令给出的结果相同
shell> ansible-playbook -i hosts -l 'groupB:groupA:!test-host' pb.yml