Is it possible to break an inventory groups file into multiple files?

One of our inventory groups files is getting huge and unwieldy. Is there a way to break groups files into multiple files?

Posted Jul 14, 2017, 4:51 PM UTC

35
somidscr21•

You can break it up. Just use the -i flag when you run ansible-playbook to point to the inventory you want. Does that cover your needs?

3
incipient_imperatorOP•

Oh, I see. Use multiple inventories, instead of a single inventory with multiple groups?

2
somidscr21•

Yes that's what I was suggesting.

2
scritty•

You can set your inventory in ansible.cfg to be a directory and ansible will use all relevant files in that directory path.

http://docs.ansible.com/ansible/intro_dynamic_inventory.html#using-inventory-directories-and-multiple-inventory-sources

In the defaults section of ansible.cfg:

[defaults]
 - inventory      = /etc/ansible/hosts
 + inventory      = /etc/ansible/inventory_directory

Then put your inventory file(s) into /etc/ansible/inventory_directory/

3
sirex007•

Yup, use a directory and -i the dir name. They don't even have to be static files, they can also be scripts for dynamic inventory or even a mixture. We have a static inventory file and a dynamic script and ansible uses both

2