Multiple simultaneous inventory sources

1,656 views
Skip to first unread message

Michael DeHaan

unread,
Mar 1, 2013, 6:10:18 PM3/1/13
to ansible...@googlegroups.com
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.

fdavis

unread,
Mar 5, 2013, 2:11:29 PM3/5/13
to ansible...@googlegroups.com
Cool, thanks @dhozac!

+1{,,,,,,,}

Chris Hoffman

unread,
Mar 6, 2013, 10:18:52 PM3/6/13
to ansible...@googlegroups.com
This sounds pretty cool.  I will have to dig into this one.  Thanks!

Stuart Reynolds

unread,
Jun 25, 2014, 2:52:19 PM6/25/14
to ansible...@googlegroups.com
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


Matt Martz

unread,
Jun 25, 2014, 2:57:14 PM6/25/14
to ansible...@googlegroups.com
I believe the recommended approach for you would be to instead use inventory scripts.  At that point, your bounds are limitless.


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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/58c14dbe-4ee6-4b7a-96ac-373ff5984fdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
ma...@sivel.net
http://sivel.net/

Michael DeHaan

unread,
Jun 25, 2014, 8:17:04 PM6/25/14
to ansible...@googlegroups.com
"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.




Stuart Reynolds

unread,
Jun 26, 2014, 3:39:46 PM6/26/14
to ansible...@googlegroups.com


On Wednesday, June 25, 2014 5:17:04 PM UTC-7, Michael DeHaan wrote:
"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



Stuart Reynolds

unread,
Jul 11, 2014, 5:51:31 PM7/11/14
to ansible...@googlegroups.com
How does -i <dir> 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



On Friday, March 1, 2013 3:10:18 PM UTC-8, Michael DeHaan wrote:

Michael DeHaan

unread,
Jul 11, 2014, 6:36:33 PM7/11/14
to ansible...@googlegroups.com
"How does -i <dir> 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.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Anatoly Zozlinsky

unread,
Apr 27, 2015, 11:24:20 AM4/27/15
to ansible...@googlegroups.com
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..

Brian Coca

unread,
Apr 27, 2015, 1:45:49 PM4/27/15
to ansible...@googlegroups.com
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
--
Brian Coca

Anatoly Zozlinsky

unread,
Apr 28, 2015, 3:44:49 AM4/28/15
to ansible...@googlegroups.com
Nice solution :)
Why didn't i think of that myself??
Reply all
Reply to author
Forward
0 new messages