# Access to inventory groups hierarchy

**URL:** <https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339>\
**Category:** Ansible Developer\
**Created:** [September 25, 2014, 5:00pm UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339 "2014-09-25T17:00:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel\_Rozlach](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@Pawel\_Rozlach](https://forum.ansible.com/u/Pawel_Rozlach)\
**Post date:** [September 25, 2014, 5:00pm UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/1 "2014-09-25T17:00:53Z")

</div>

Hi!

I would like to start a discussion about access to inventory groups hierarchy. I have already created an [issue](https://github.com/ansible/ansible/issues/9070) describing the problem.

Our use case is re-creating inventory groups hierarchy in Icinga`s configuration, so that we have 1:1 mapping betwean hostgroups and inventory groups. One way do achieve it would be to create a new variable “group\_children” just like i.e. ‘groups’, but instead of a list of host - it would contain list of child groups or empty list if there are none.

So, assuming that we have inventory like this:

[market-za:children]  
front-za  
backend-za

[front-za]  
front1  
front2

[backend-za]  
backend1  
backend2

we would have:

group\_children[‘market-za’] = [‘front-za’, ‘backend-za’]  
group\_children[‘front-za’] =

What do you think about that ?

Thanks in advance for a reply.  
pr

---

<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:** [September 30, 2014, 10:35am UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/2 "2014-09-30T10:35:45Z")

</div>

​Sorry I didn't reply earlier, I hoped for other people having a use case  
here too :)​

> group\_children['market-za'] = ['front-za', 'backend-za']  
> group\_children['front-za'] =

​This sounds good to me. I'd add a var for parent groups to that, too, as  
this is also available in the Group object.  
Given hosts have a 'group\_names' containing all groups (upwards  
recursively​) it is a member of, it might also makes sense here to have a  
var containing only the direct parents.

So:  
- group\_children has keys for every group  
- group\_parents has keys for every group  
- group\_names and group\_names\_parents would exist for every host, the  
former alreqady exists.

Given this, a word on a related use case that is covered by the same  
subject, and in which I have an interest.

I would like to be able to more easily target multiple sets of clusters  
within the same playbook in a serialized way, e.g. applying the same role  
to deploy different apps.  
Given say 100 tomcat clusters, deployed with 1 set of roles in the same  
way, but with different apps, parametrized via the inventory, I need to  
deploy one node at a time.

Now, this is possible with serial: 1 of course, but when a deploy consists  
of upgrading several related application, it would be a big benefit to be  
able to deploy several clusters at the same time, but each node within a  
given cluster 1 at a time.  
So, functionally, that would be something like "serial: per node in  
cluster".

Code wise, this would translate into runner using serial batches, where the  
first batch contains 'all the first nodes in the cluster', the next batch  
all second nodes, and so on.

I'm not sure ho wthis could be easily defined though. Given all nodes of a  
paticular cluster are part of a particular application group, and those  
application groups would be part of, say, a tomcat group,  
parent/grandparent group membership could be looked at, but so far I  
couldn't think of a decent way to model that.

Thoughts?

&nbsp;&nbsp;Serge

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [October 1, 2014, 7:15am UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/3 "2014-10-01T07:15:28Z")

</div>

> [snip]
> 
> Code wise, this would translate into runner using serial batches, where the first batch contains ‘all the first nodes in the cluster’, the next batch all second nodes, and so on.
> 
> I’m not sure ho wthis could be easily defined though. Given all nodes of a paticular cluster are part of a particular application group, and those application groups would be part of, say, a tomcat group, parent/grandparent group membership could be looked at, but so far I couldn’t think of a decent way to model that.

Not sure if that what you meant, but you could say something like that:

- hosts: tomcats  
serial: 1/(region-\*)

i.e. give a pattern for the child groups under the tomcats group. Less magic involved.

---

<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:** [October 1, 2014, 7:32am UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/4 "2014-10-01T07:32:31Z")

</div>

Something like that yes​!

What do you mean exactly by "less magic involved"?

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [October 1, 2014, 8:04am UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/5 "2014-10-01T08:04:10Z")

</div>

you were talking about looking at group relationships etc. It sounded like ansible should just figure out on its own how to partition your hosts to clusters, hence magic 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 1, 2014, 12:42pm UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/6 "2014-10-01T12:42:05Z")

</div>

I’ve closed this ticket as I don’t think we need to clutter up the variable space with a lot of magic and objects about how this works.

If you wanted to create some private fact module that used the inventory API, technically, you could, but I fear this is too far down the rabbit hole, and would bloat up the various dictionaries we are passing around for template purposes.

I’d like to take a step back to understand your use case and suggest perhaps better ways of writing your playbooks and templates, or organizing your icinga configuration, that could make this easier.

---

<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:** [October 1, 2014, 12:45pm UTC](https://forum.ansible.com/t/access-to-inventory-groups-hierarchy/16339/7 "2014-10-01T12:45:32Z")

</div>

​The vars things was more the request of the OP.​  
​My use case whas about serializing per clusternode, as describe in a  
previous post. Not sure what info I could add to that.​
