I have an ansible hosts file that looks like that:
[myhosts]
192.168.0.1
192.168.0.2
[group1:children]
myhosts
[group2:children]
myhosts
Along side with group vars files for group1 and group2 (and incidentally for myhosts) that are declaring some common variables but with different values.
Here is my directory layout (that follows the best pratices):
hosts
main.yml
group_vars/
group1.yml
group2.yml
myhosts.yml
Therefore, both group vars files for group1 and group2 are automatically included by ansible when an host belongs to both groups.
For the record, I am callinng ansible on my playblook with the following pattern as target (specified in command line):
192.168.0.1:&group1
Considering that, how can I make ansible include only the group vars file associated to group1 (and children group myhosts) ? Is that possible ?
An alternate solution would be renaming the group vars files of group1 and group2 to something different (to prevent automatic includes) and includes those in separate "proxy" playbooks, specific to each subgroup, but this seems less clean to me.
Note: for the moment it is not the case, but in the futur it is likely that group1 and group2 would have few hosts not in common.