# Reusing inventory config

**URL:** <https://forum.ansible.com/t/reusing-inventory-config/15398>\
**Category:** Ansible Project\
**Created:** [June 4, 2014, 1:20am UTC](https://forum.ansible.com/t/reusing-inventory-config/15398 "2014-06-04T01:20:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Mahemoff](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Michael\_Mahemoff](https://forum.ansible.com/u/Michael_Mahemoff)\
**Post date:** [June 4, 2014, 1:20am UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/1 "2014-06-04T01:20:30Z")

</div>

As I have separate “staging” and “production” inventory files, I end up duplicating some group compositions (e.g. databases:children is mysql:children and redis:children, that kind of thing). I’m wondering if there’s a way to consolidate that logic, such as a directive to include a file. Or maybe some trick I’m missing here.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 4, 2014, 2:08pm UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/2 "2014-06-04T14:08:27Z")

</div>

If you’re dealing with any significant number of hosts (ie. more than a hundred), we generally recommend using a dynamic inventory script of some kind. Beyond that, the INI syntax doesn’t really allow for any includes unfortunately.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [June 5, 2014, 7:05am UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/3 "2014-06-05T07:05:41Z")

</div>

I do the per environment inventories too (partly because they're  
datacenter/vagrant)  
and had a few groups just to target one-off plays.

My per-environment settings usually tuck into

[all:vars]

in the inventory - I've no idea how I'm going to map that to a dynamic inventory  
yet, probably a lot of set\_fact roles to set everything up.

I keep them in step by diffing ☹

Re: the group composition - I needed that for some one-off plays, it  
turns out you can target multiple groups in a play with something like

.....  
- hosts: mysql:redis  
&nbsp;&nbsp;sudo: yes  
&nbsp;&nbsp;tasks:  
.....

---

<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:** [June 6, 2014, 12:34pm UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/4 "2014-06-06T12:34:16Z")

</div>

Don’t do “all:vars”, use a “group\_vars/all” file instead.

Not only is it cleaner for a static inventory, but it’s usable with dynamic ones as well.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [June 6, 2014, 1:08pm UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/5 "2014-06-06T13:08:09Z")

</div>

Yeah we're about to try some of the cloud providers, I know this is  
going to bite us.

problem with group\_vars/all is that it's 'in the tree' - I'm trying to  
find a way to  
have preprod\_hosts and production\_hosts contain everything environment-specific,  
so we can ensure roles/ group\_vars/ etc. don't vary across different  
environments.

---

<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:** [June 8, 2014, 3:29pm UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/6 "2014-06-08T15:29:58Z")

</div>

“problem with group\_vars/all is that it’s ‘in the tree’ - I’m trying to  
find a way to”

You can keep this alongside your inventory (which most people do) rather than alongside your playbook, if you like.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [June 9, 2014, 3:42pm UTC](https://forum.ansible.com/t/reusing-inventory-config/15398/7 "2014-06-09T15:42:22Z")

</div>

Ah, mine are all lumped in together, like this:

ansible-mystack:$ tree -L 1  
.  
├── Vagrantfile  
├── ansible.cfg  
├── group\_vars  
├── preprod\_hosts  
├── prod\_hosts  
├── roles  
├── site.yml  
└── vagrant\_hosts

Are you talking about having a group\_vars per inventory then?  
Trying to figure out how that would look.
