Ansible - run playbooks from different directory

Ron_1984

New Member
Joined
Feb 8, 2021
Messages
18
Reaction score
4
Credits
251
Hi

Can I store ansible playbooks in different directories and my customized ansible.cfg stored under different directories and run the playbooks?
It seems that ansible assumes that the ansible.cfg file exists in the current working directory so when I try to call a playbook that exists in a subdirectory it will fail to load the roles and other stuff.

Is it possible to store playbook in different directories?

Can you help?
 


You can put playbook in any directory (that you have permission to).
You can edit ansible.cfg, or you can just type out full paths to yml files.
If you write the playbooks right, it doesn't matter where hosts, and roles are.
But as a rule I keep all dependencies in the same directory.
 
You can put playbook in any directory (that you have permission to).
You can edit ansible.cfg, or you can just type out full paths to yml files.
If you write the playbooks right, it doesn't matter where hosts, and roles are.
But as a rule I keep all dependencies in the same directory.
is there any parameter to hardcode the playbook location in the ansible.cfg?
 
# (pathspec) Colon separated paths in which Ansible will search for collections content. Collections must be in nested *subdirectories*, not directly in these directories. For example, if ``COLLECTIONS_PATHS`` includes ``~/.ansible/collections``, and you want to add ``my.collection`` to that directory, it must be saved as ``~/.ansible/collections/ansible_collections/my/collection``.

;collections_path=~/.ansible/collections:/usr/share/ansible/collections

# (boolean) A boolean to enable or disable scanning the sys.path for installed collections
;collections_scan_sys_path=True

Ansible 5 will auto-generate an example config file for you.
ansible-config init --disabled -t all > ansible.cfg
 
If you just use the defaults, this commands will show you where it expects things.

ansible --version

ansible [core 2.12.5]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 12.0.1 20220308 (Red Hat 12.0.1-0)]
jinja version = 3.0.3
libyaml = True
 

Members online


Top