I'm managing a number of clusters, and I wanted to consolidate multiple inventory files into a single inventory that looks effectively like this:
all:
children:
cluster_one:
children:
controller:
hosts:
host1:
host2:
host3:
compute:
hosts:
host4:
host5:
host6:
cluster_two:
children:
controller:
hosts:
host11:
host12:
host13:
I was expecting this to end up parsed like this:
[cluster_one]
host1
host2
host3
host4
host5
host6
[cluster_two]
host11
host12
host13
[controller]
host1
host2
host3
host11
host12
host13
[compute]
host4
host5
host6
With that structure, I would be able to ask for "controllers in
cluster_one" with the host pattern cluster_one:&controller, or if
I wanted all controllers across all clusters I could just ask for
controller. Convenient!
Unfortunately, it's actually parsed like this:
[cluster_one]
host1
host2
host3
host4
host5
host6
[cluster_two]
host11
host12
host13
[controller]
host1
host2
host3
host11
host12
host13
[compute]
host4
host5
host6
[cluster_one:children]
controller
compute
[cluster_two:children]
controller
Note the two extra entries at the bottom that make the controller
and compute groups children of their respecting "parents" in the
YAML file, rather than making only their hosts members of the
parents.
So for example if I run ansible -i example.yml --list-hosts cluster_one, I get:
hosts (9):
host1
host2
host3
host11
host12
host13
host4
host5
host6
That was unexpected and made me sad. I can obviously restructure the inventory so that it works (e.g. by using the INI-format inventory shown here, or re-structuring the YAML for a similar structure), but those solutions involve listing each host multiple times, which means it's possible for things to get out of sync.
Is there a way to structure the inventory that gets me the grouping I want without having to explicitly list hosts in multiple groups?