Ansible nested dictionary seems to do weird stuff with identical sub-groups

21 views
Skip to first unread message

I Viridis

unread,
Oct 11, 2018, 5:06:45 AM10/11/18
to Ansible Project
 # inventory.yml
   europe:
     children:
       germany:
         children:
           on-premise:
             hosts:
               127.0.0.1:
           datacenter:
             hosts:
               127.0.0.2:
       france:
         children:
           on-premise:
             hosts:
               127.0.0.3:
           datacenter:
             hosts:
               127.0.0.4:


Running the following command with different `--limit` options:

ansible-playbook -i inventory.yml random-playbook.yml --limit 'some-limit


- `europe` I expect to run 127.0.0.1, 127.0.0.2, 127.0.0.3, 127.0.0.4
- `on-premise` I expect to run 127.0.0.1, 127.0.0.3
- `datacenter` I expect run 127.0.0.2, 127.0.0.4
- `germany` I expect to run 127.0.0.1, 127.0.0.2
- `france` I expect to run 127.0.0.3, 127.0.0.4

Now, my issue:

- Europe works as expected
- on-premise works as expected
- datacenter works as expected
- germany runs 127.0.0.1, 127.0.0.2, 127.0.0.3, 127.0.0.4
- france runs 127.0.0.1, 127.0.0.2, 127.0.0.3, 127.0.0.4

After playing with it for a while, it seemed like this behaviour is gone once you don't have 2 on-premise or 2 datacenter children in germany and france.

It feels like while creating the host list it is just like 'alright, france, on-premise and datacenter are children ... get all the children/hosts of that group' ... after which he finds hosts in `datacenter` group that never belonged to France in the first place.

I was just wondering if I'm doing this wrong, or whether this is intended behaviour

Brian Coca

unread,
Oct 11, 2018, 2:58:17 PM10/11/18
to Ansible Project
Those are not 'sub-groups' they are the same group. you are giving
them a parent/child relationship but all groups are 'global' so the
same name refers to the same group.
Only one 'on-premise' group exists, it is a chidl of france AND
germany, any hosts you assign to it at any point are always part of
that group.

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages