# Multiple simultaneous inventory sources

**URL:** <https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442>\
**Category:** Ansible Project\
**Created:** [March 1, 2013, 11:10pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442 "2013-03-01T23:10:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 1, 2013, 11:10pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/1 "2013-03-01T23:10:18Z")

</div>

I've just merged a very nice patch set from @dhozac that enables the  
inventory file to be a directory

If it is a directory, it operates much like a traditional "conf.d"  
structure, except it allows both inventory files and  
inventory scripts to be comingled.

This means that you can use EC2 and physical-file-based inventory  
together, and then specify a "-i" inside the  
directory to specifically target one and not the other.

When using this, the patch is structured such that "group\_vars" and  
"host\_vars" structures live \*inside\* the directory, so it's always  
going to work whether you use the whole directory of inventroy sources  
or just one file on the inside.

I know this was a much requested feature so this is great to see...  
multiple dynamic inventory sources at once, conf.d files,  
or both, at the same time in any combination you want!

So thanks to Daniel for this one. It will be up on the documentation  
pages eventually.

---

<div class="post-metadata">

**Author:** ![fdavis](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fdavis](https://forum.ansible.com/u/fdavis)\
**Post date:** [March 5, 2013, 7:11pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/2 "2013-03-05T19:11:29Z")

</div>

Cool, thanks @dhozac!

+1{,}

---

<div class="post-metadata">

**Author:** ![Chris\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@Chris\_Hoffman](https://forum.ansible.com/u/Chris_Hoffman)\
**Post date:** [March 7, 2013, 3:18am UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/3 "2013-03-07T03:18:52Z")

</div>

This sounds pretty cool. I will have to dig into this one. Thanks!

---

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Stuart\_Reynolds](https://forum.ansible.com/u/Stuart_Reynolds)\
**Post date:** [June 25, 2014, 6:52pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/4 "2014-06-25T18:52:19Z")

</div>

Is there any support for specifying multiple specific inventory files. For example, I may have the following clusters of service machines.

ProdClusterInventory  
StagingClusterInventory  
QAClusterInventory  
DevClusterInventory  
CommonClusterInventory

Prod thru Dev all need to refer to database machine held in the CommonClusterInventory – so naturally, I often want playbooks to refer to machine groups in, say ,ProdClusterInventory and CommonClusterInventory.

ansible -i appears to only allow a single inventory file to be specified. Using -i to refer to a directory:

DevCluster/  
DevInventory

CommonInventory

means that CommonInventory is duplicate many times. (And I can’t commit symlinks to our source control)

Ideally (I think), I should be able to say an inventory file includes another.

- Stuart

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 25, 2014, 6:56pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/5 "2014-06-25T18:56:28Z")

</div>

I believe the recommended approach for you would be to instead use inventory scripts. At that point, your bounds are limitless.

[http://docs.ansible.com/developing\_inventory.html](http://docs.ansible.com/developing_inventory.html)

An inventory script can use mostly anything as it’s data source. You just need to write the code to handle your scenario.

---

<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 26, 2014, 12:17am UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/6 "2014-06-26T00:17:01Z")

</div>

“means that CommonInventory is duplicate many times. (And I can’t commit symlinks to our source control)”

It sounds like you need to better arrange groups such that you can specify groups, rather than breaking them up into seperate inventories maybe.

Though for larger cases or if you want something more custom, inventory scripts are useful, and if using directories, you can even do things like speak dynamically to Rackspace and EC2 and GCE all in the same call.

---

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Stuart\_Reynolds](https://forum.ansible.com/u/Stuart_Reynolds)\
**Post date:** [June 26, 2014, 7:39pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/7 "2014-06-26T19:39:45Z")

</div>

> “means that CommonInventory is duplicate many times. (And I can’t commit symlinks to our source control)”
> 
> It sounds like you need to better arrange groups such that you can specify groups, rather than breaking them up into seperate inventories maybe.

Possibly, the good advice in your best practices document is to separate production/staging/qa/dev …

I think this is essential for us.

> Though for larger cases or if you want something more custom, inventory scripts are useful, and if using directories, you can even do things like speak dynamically to Rackspace and EC2 and GCE all in the same call.

Yes – looking at that route. Now, hacking ec.py to provide a limited view of all our ec2 instances.

Thanks,

- Stuart

---

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Stuart\_Reynolds](https://forum.ansible.com/u/Stuart_Reynolds)\
**Post date:** [July 11, 2014, 9:51pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/8 "2014-07-11T21:51:31Z")

</div>

How does -i determine which files are included and which are not? Can I have edit backups (./aaa~), README.txt, etc… in that directory?

Also, are there any plans to allow multiple specific inventory files? (It looks like a common request – are problems anticipated with such a feature?

- Stu

---

<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:** [July 11, 2014, 10:36pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/9 "2014-07-11T22:36:28Z")

</div>

“How does -i determine which files are included and which are not? Can I have edit backups (./aaa~), README.txt, etc… in that directory?”

It ignores files ending in “.ini” as well as files ending in known backup extensions or files starting with dot (hidden files)

Take a look at dir.py in the inventory/ subtree of the source if you are really curious… but basically most backup extensions will be ignored.

---

<div class="post-metadata">

**Author:** ![Anatoly\_Zozlinsky](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Anatoly\_Zozlinsky](https://forum.ansible.com/u/Anatoly_Zozlinsky)\
**Post date:** [April 26, 2015, 3:33pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/10 "2015-04-26T15:33:34Z")

</div>

Hi

It is possible to provide a list of files (not directory) to -i option ??

i have next use case:

inventories/amazon/ec2.py  
inventories/gce/gce.py

inventories/inventory

ec2 and gce provide different group names, like:  
tag\_Name\_stage for amazon

tag\_stage for google

(or even more complex)

in inventory file i created

[tag\_stage]  
[tag\_Name\_stage]

[app\_stage:children]  
tag\_Name\_stage

tag\_stage

and when in playbook i use hosts: “app\_stage”

i want to put -i inventories/amazon/ec2.py , inventories/inventory  
or  
i want to put -i inventories/gce/gce.py , inventories/inventory

and not both

thanks…

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 27, 2015, 5:45pm UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/11 "2015-04-27T17:45:45Z")

</div>

no, but you can symlink those files(and their configs) into a  
directory and provide that.

inventories/amazon/ec2.py  
inventories/gce/gce.py  
inventories/inventory

inventories/withgce/inventory  
inventories/withgce/gce.py

inventories/withec2/inventory  
inventories/withec2/ec2.py

---

<div class="post-metadata">

**Author:** ![Anatoly\_Zozlinsky](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Anatoly\_Zozlinsky](https://forum.ansible.com/u/Anatoly_Zozlinsky)\
**Post date:** [April 28, 2015, 7:44am UTC](https://forum.ansible.com/t/multiple-simultaneous-inventory-sources/12442/12 "2015-04-28T07:44:49Z")

</div>

Nice solution 🙂  
Why didn’t i think of that myself??
