Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: specify inventory file inside playbook

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?

like image 997
user2221830 Avatar asked Dec 06 '17 19:12

user2221830


1 Answers

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.

like image 88
Konstantin Suvorov Avatar answered Oct 18 '22 22:10

Konstantin Suvorov