Bootstrap FreeKB - Ansible - Define roles path directories using the ANSIBLE_ROLES_PATH variable
Ansible - Define roles path directories using the ANSIBLE_ROLES_PATH variable

Updated:   |  Ansible articles

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

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

 

By default, roles_path directive 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.

 

The export command can be used to define the ANSIBLE_ROLES_PATH variable.

export ANSIBLE_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

 

The unset command can be used to undefine the ANSIBLE_ROLES_PATH variable.

unset ANSIBLE_ROLES_PATH

 




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 50d1eb in the box below so that we can be sure you are a human.