I have a directory structure under which I am keeping my playbooks like follow:
/home/monk/
|_____Ansible_work
|_____[ansible.cfg]
|_____[playbook_dir_1]
| |_______playbook_1.yml
|_____[playbook_dir_2]
| |_______playbook_2.yml
|_____[playbook_dir_3]
| |_______playbook_3.yml
|_____[playbook_dir_4]
| |_______playbook_4.yml
|_____[inventory]
|___[inventory_1]
|___[inventory_2]
I am currently executing my playbooks like below from ansible_work dir:
ansible-playbook -i inventory/inventory_1 playbook_dir_1/playbook_1.yml
or
ansible-playbook -i inventory/inventory_1 playbook_dir_1/playbook_2.yml
or
ansible-playbook -i inventory/inventory_2 playbook_dir_1/playbook_1.yml
Each playbook need to refer to some of the variables set in ansible.cfg like log_path ,role_path etc. Everything works fine.
Now I have been told that, I should make the configuration flexible enough such that these playbooks can be executed from any location when given full path of inventory and playbook. (which seems fair requirement)
But as my playbooks refer local copy of ansible.cfg , the content set within this local ansible.cfg will not be set if I trigger executin from any point apart from /home/monk/ansible_work/ dir.
By default Ansible.cfg lookup priority is as follow:
* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory) <--------------I am currently using this
* .ansible.cfg (in the home directory) <--------------Cannot use this as multiple users will be running the PB
* /etc/ansible/ansible.cfg <--------------Cannot set this as , we do not have admin rights.
Question:
How to make playbooks independent of ansible.cfg and still set the configuration like DEFAULT_LOG_PATH ,DEFAULT_ROLES_PATH etc. ?
OR
How to make playbook executable from any directory but still it keep sourcing a user created ansible.cfg ? which is not present in the three default locations.