12

So from what I gather, we can use ansible.cfg to set the default inventory file that ansible looks for when running a playbook.

We can also override that inventory by using the -i parameter when running an ansible playbook via the command line.

Is there a way for me to specify a specific special inventory file inside a playbook without using the command line or changing the ansible.cfg file?

user2221830
  • 163
  • 2
  • 11

1 Answers1

3

You can form a dynamic inventory from inside your playbook using add_host module.
But you will have to write some inventory files parsers to feed correct parameters to add_host.

In general this is the wrong way to go. You should have playbooks and inventories separated.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • What i'm trying to accomplish, and this may be against Ansible's best practices, Is a nested playbook that calls upon another playbook that has an inventory file managed by another team. So far Ansible looks for everything in one central location, but I need the flexibility of separating out hosts to be controlled by different teams that own those hosts. – user2221830 Dec 06 '17 at 20:43
  • You may want to explore Ansible API a bit to programmatically call different playbooks with different inventories from a central piece of code. – Konstantin Suvorov Dec 07 '17 at 04:05