Ansible: specify inventory file inside playbook
Asked Answered
G

1

13

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?

Gonion answered 6/12, 2017 at 19:20 Comment(0)
I
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.

Inebriety answered 6/12, 2017 at 20:21 Comment(2)
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.Gonion
You may want to explore Ansible API a bit to programmatically call different playbooks with different inventories from a central piece of code.Inebriety

© 2022 - 2024 — McMap. All rights reserved.