# Split up an ansible inventory

**URL:** <https://forum.ansible.com/t/split-up-an-ansible-inventory/14405>\
**Category:** Ansible Project\
**Created:** [January 23, 2014, 9:39am UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405 "2014-01-23T09:39:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [January 23, 2014, 9:39am UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/1 "2014-01-23T09:39:22Z")

</div>

Hi,

I have my production inventory in one file (inventory/prod) and I'm  
looking for a way to split up this file. For instance, I would like to  
have a "servers" file and a "groups" file. The important thing is that  
I need to define objects (hosts, groups) in the first file and use  
them in the second.

I thought I had found a solution with the -i directory option, but  
this doesn't seem to "concatenate" the files. It treats them as  
independent inventories, so I get errors.

Is there a way to do that ?

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:** [January 23, 2014, 10:10am UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/2 "2014-01-23T10:10:37Z")

</div>

​You can point -i to a directory which can have several files and  
subdirectories.​

---

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [January 23, 2014, 11:04am UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/3 "2014-01-23T11:04:47Z")

</div>

Le 14/01/23 11:10, Serge van Ginderachter claviotta :

---

<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:** [January 23, 2014, 11:57am UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/4 "2014-01-23T11:57:37Z")

</div>

​That's true. You'll need to look at the order in which the files are  
parsed, and make sure you repeat certain references,

It's enough to e.g. define an empty group, in the one file which is defined  
with hosts in another, etc.​

---

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [January 23, 2014, 1:23pm UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/5 "2014-01-23T13:23:16Z")

</div>

Le 14/01/23 12:57, Serge van Ginderachter claviotta :

> \> Yes, that's exactly what I said, but this doesn't work as expected,  
> \> because in the second file I can't reference objects that are created  
> \> in the first.  
> \>
> 
> ​That's true. You'll need to look at the order in which the files are  
> parsed, and make sure you repeat certain references,
> 
> It's enough to e.g. define an empty group, in the one file which is defined  
> with hosts in another, etc.​

I'm sorry but I don't think that information redundancy will simplify  
my inventory… This is really not a solution.

Don't you think the expected behavior would be that all  
non-executables files in the inventory directory be concatenated  
before being read by lib/ansible/inventory/dir.py ?

All the static files in the directory should be parsed as a unique  
inventory.

---

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [January 23, 2014, 3:49pm UTC](https://forum.ansible.com/t/split-up-an-ansible-inventory/14405/6 "2014-01-23T15:49:26Z")

</div>

Le 14/01/23 14:23, Guillaume Subiron claviotta :

> Le 14/01/23 12:57, Serge van Ginderachter claviotta :  
> \>  
> \> \> Yes, that's exactly what I said, but this doesn't work as expected,  
> \> \> because in the second file I can't reference objects that are created  
> \> \> in the first.  
> \> \>  
> \>  
> \> ​That's true. You'll need to look at the order in which the files are  
> \> parsed, and make sure you repeat certain references,  
> \>  
> \> It's enough to e.g. define an empty group, in the one file which is defined  
> \> with hosts in another, etc.​
> 
> I'm sorry but I don't think that information redundancy will simplify  
> my inventory… This is really not a solution.
> 
> Don't you think the expected behavior would be that all  
> non-executables files in the inventory directory be concatenated  
> before being read by lib/ansible/inventory/dir.py ?
> 
> All the static files in the directory should be parsed as a unique  
> inventory.

I made a pull request : [https://github.com/ansible/ansible/pull/5735](https://github.com/ansible/ansible/pull/5735)
