Bootstrap FreeKB - Ansible - Define roles path directories using the roles_path directive in ansible.cfg
Ansible - Define roles path directories using the roles_path directive in ansible.cfg

Updated:   |  Ansible articles

Let's say your playbook wants to use the "foo" role.

---
- hosts: all
  roles:
    - foo
...

 

By default, roles_path in ansible.cfg is commented out and the ANSIBLE_ROLES_PATH variable is undefined.

# roles_path = /usr/local/roles

 

When roles_path directive is commented out and the ANSIBLE_ROLES_PATH variable is undefined, Ansible will search the following directories for the "foo" role:

  • The directory that contains your playbook (e.g. /home/john.doe/foo)
  • /usr/share/ansible/roles
  • /etc/ansible/roles
  • /home/username/.ansible/roles

The ansible-galaxy list command can be used to list the roles directories. In this example, the default roles directories (/usr/share/ansible/roles, /etc/ansible/roles, and /home/john.doe/.ansible/roles) are being used.

~]# ansible-galaxy list
# /usr/share/ansible/roles
# /etc/ansible/roles
[WARNING]: - the configured path /home/john.doe/.ansible/roles does not exist.

 

Let's say you define some other roles_path in ansible.cfg.

roles_path = /usr/local/ansible/roles

 

And then the ansible-galaxy list command can be used to confirm the roles directories.

~]# ansible-galaxy list
# /usr/local/ansible/roles

 

It is noteworthy that you have a role that resides in some other directory, say /usr/local/testing/roles, the role can be used by including the absolute path to the role in your playbook.

---
- hosts: all
  roles:
    - /usr/local/testing/roles/foo

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f5986a in the box below so that we can be sure you are a human.