I have a playbook like
- hosts: hostA
roles:
- roleA
- roleB
- hosts: hostB
roles:
- roleA
- roleC
and an inventory
all:
children:
hostA:
hosts:
machine1
hostB:
hosts:
machine2
So far, everything works fine. But now I have a second environment with inventory
all:
children:
hostA:
hosts:
machine3
hostB:
hosts:
machine3
RoleA gets executed twice when I run the playbook. Is there a way to prevent that?
The most DRY, straightforwad and easy way to "fix" this is:
- name: run common roles for both groups
hosts: hostA:hostB
roles:
- roleA
- name: run specific roles for group A
hosts: hostA
gather_facts: false
roles:
- roleB
- name: run specific roles for group B
hosts: hostB
gather_facts: false
roles:
- roleC
If you are unclear with the meaning of hosts: hostA:hostB in the first play, have a look at ansible hosts/group patterns
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With