# How can I determine child groups

**URL:** <https://forum.ansible.com/t/how-can-i-determine-child-groups/12960>\
**Category:** Ansible Project\
**Created:** [June 14, 2013, 7:33am UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960 "2013-06-14T07:33:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jurgen\_Haas1](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@Jurgen\_Haas1](https://forum.ansible.com/u/Jurgen_Haas1)\
**Post date:** [June 14, 2013, 7:33am UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960/1 "2013-06-14T07:33:35Z")

</div>

Is there a variable which tells me which groups are childs of what other groups?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 14, 2013, 12:23pm UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960/2 "2013-06-14T12:23:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas1](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@Jurgen\_Haas1](https://forum.ansible.com/u/Jurgen_Haas1)\
**Post date:** [June 14, 2013, 2:42pm UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960/3 "2013-06-14T14:42:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [June 14, 2013, 2:52pm UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960/4 "2013-06-14T14:52:32Z")

</div>

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](https://github.com/ginsys/ansible-plugins/blob/devel/bin/ansible-vars)

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 14, 2013, 3:41pm UTC](https://forum.ansible.com/t/how-can-i-determine-child-groups/12960/5 "2013-06-14T15:41:37Z")

</div>

I would totally recommend the inventory API as it has lots of methods for exploring the groups topology.
