# centralizing groups of groups, strategy that works for both dynamic and static inventory

**URL:** <https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933>\
**Category:** Ansible Project\
**Created:** [August 13, 2014, 3:38pm UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933 "2014-08-13T15:38:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Simon](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Matthew\_Simon](https://forum.ansible.com/u/Matthew_Simon)\
**Post date:** [August 13, 2014, 3:38pm UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933/1 "2014-08-13T15:38:57Z")

</div>

Hello All!

For many of my plays, I use groups of groups to handle items common to several systems. For example, given an inventory file such as:

[jenkins\_masters]

host1

[jenkins\_slaves]  
slave1  
slave2

slave3

[jenkins\_servers:children]  
jenkins\_masters  
jenkins\_slaves

The playbook might look like:

- hosts: jenkins\_servers  
roles:

- java

- hosts: jenkins\_masters

roles:

- jenkins

- hosts: jenkins\_slaves  
roles:

- java\_buildtools

I’m looking for a way to centralize the population of these top level groups; meaning, no matter what inventory is used, all hosts in jenkins\_masters and jenkins\_slaves are added to jenkins\_servers.

When using dynamic inventory, I found it was very convenient to add a static inventory file called rollup\_groups that contains no hosts, but just:

[jenkins\_masters]  
[jenkins\_slaves]

[jenkins\_servers:children]  
jenkins\_masters  
jenkins\_slaves

When referring to the directory that contains this and the dynamic inventory script, the hosts and basic group membership come from the cloud, and the parent group gets taken care by this file.

To re-use this same method with static host inventories, the only way I can see is to put each inventory file in a separate directory along with a copy of rollup groups. But I don’t feel awesome about that solution - having many copies of the same file bothers me.

Does anybody have ideas about how else to tackle this?

Thanks,

Matt

---

<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:** [August 14, 2014, 11:45am UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933/2 "2014-08-14T11:45:58Z")

</div>

Mixing groups between dynamic and static works in Ansible 1.7 and higher, so if you are not running that version, I’d upgrade.

"To re-use this same method with static host inventories, the only way I can see is to put each inventory file in a separate directory along with a copy of rollup groups. "

I don’t understand this part of the question.

---

<div class="post-metadata">

**Author:** ![Matthew\_Simon](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Matthew\_Simon](https://forum.ansible.com/u/Matthew_Simon)\
**Post date:** [August 15, 2014, 12:19pm UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933/3 "2014-08-15T12:19:01Z")

</div>

Thanks for the response Michael.

> Mixing groups between dynamic and static works in Ansible 1.7 and higher, so if you are not running that version, I’d upgrade.

Yes, exactly. This is what I’m doing with my cloud inventories. The host inventory and basic group info comes via rax.py, and then a static file ‘rollup\_groups’ that I described below is used as well. That’s working great for me.

> "To re-use this same method with static host inventories, the only way I can see is to put each inventory file in a separate directory along with a copy of rollup groups. "
> 
> I don’t understand this part of the question.

I’m looking for something similar with static inventories. What I was trying to explain was I though I could combine a static host list with my rollup groups file, but only if I put each static inventory in a separate directory with a copy of rollup groups. As far as I am aware, that’s the only way to combine inventories.

But I’m open to any other option…For example, if there was a way to combine inventories without having them in the same directory, or if there was a task-based solution to automatically populate parent groups.

Thanks!

---

<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:** [August 15, 2014, 2:30pm UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933/4 "2014-08-15T14:30:24Z")

</div>

To me, that is not really needed, but it could make a corner case work, so  
having details would help to understand your setup.

​Could you elaborate why that would be needed, and how this would look  
​exactly?

Serge

---

<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:** [August 16, 2014, 2:54pm UTC](https://forum.ansible.com/t/centralizing-groups-of-groups-strategy-that-works-for-both-dynamic-and-static-inventory/15933/5 "2014-08-16T14:54:59Z")

</div>

“I’m looking for something similar with static inventories. What I was trying to explain was I though I could combine a static host list with my rollup groups file, but only if I put each static inventory in a separate directory with a copy of rollup groups. As far as I am aware, that’s the only way to combine inventories.”

You can already reference one groupname (on 1.7 or devel) in another inventory file, so AFAIK what you speak of is possible, or I’m not understanding it completely.

“But I’m open to any other option…For example, if there was a way to combine inventories without having them in the same directory, or if there was a task-based solution to automatically populate parent groups.”

Symlinks.

and if you really want a giant sledgehammer of awesome for inventory management - Ansible Tower. It provides graphical inventory editing and you can sync a group with any inventory file, and has some really nice things to control sync’ing of cloud inventories - on different schedules - on playbook launches, with cache timeouts, and lots of things like that.
