Is there a variable which tells me which groups are childs of what other groups?
There is not, but you could use the inventory API.
(However, you might not need to, checking if the host is in a parent group, etc, is straightforward)
Is this something you need for a playbook? Can you help me understand the use case?
The principle idea I’m currently exploring is whether it is possible to generate a graphical representation of the server farm being managed by Ansible. I would like to utilize PlantUML for this and want to achieve something where I get a container in the graphic for each top level group in the inventory and with these containers - if available - I’d like to generate sub-containers in the graphic. Within those container (representing inventory groups) I will then get my hosts together with a set of parameters from the inventory.
This would provide a nice and easy to understand overview of your server architecture.
The way I wanted to go about this was to use a loop in a template for each group and call a sub-template for each sub-group and call another template for each host. That would provide us with a nested loop of infinite granularity, depending on how deep one was nesting their groups in the inventory.
If that worked, I would then try and make this as configurable as possible so that it is beneficial for public distribution and use.
What do you think?
I think you'll have a hard time doing that with playbooks. Better use the
inventory api.
I did something comparable, not graphically, but with a cli tool, that
basically does something like this (amongst other options):
$ ansible-vars dataengine-dov --list-groups | cut -d\| -f1
.. dataengine-dov(2)
... dataengine-dov-paleo-neo-oe(3)
... dataengine-dov-paleo-neo-on(3)
... dataengine-dov-paleo-neo-pr(3)
... dataengine-dovint-oe(3)
... dataengine-dovint-on(3)
... dataengine-dovint-pr(3)
The key to building a tree oout of your inventory is the depth parameter
(the number between parentheses) each group has.
In my experience, this value is however not allways consequently exact, but
that's another story.
You can find my script here:
https://github.com/ginsys/ansible-plugins/blob/devel/bin/ansible-vars
Serge
I would totally recommend the inventory API as it has lots of methods for exploring the groups topology.