I observed that roles downloaded from galaxy get installed inside the roles/
directory, where we already have our in-house ones, making quite hard to distiguish between external ones and internal ones.
Is there a way to keep them in separated directories, so we can avoid confusions?
In most cases I would expect to have a script that is updating the galaxy ones and that we would not modify them internally.
I think there is no standard way of doing this but you can use Ansibles behavior to your advantage.
Ansible searches in two locations for roles:
- In the
roles
directory relative to your playbook
- The path you configured in your
ansible.cfg
What you now need to do depends on where you actually store you roles. We are storing our roles relative to our playbooks, so everything is in the same git repo.
Now you could define in your ansible.cfg
to look for roles in an additional folder:
roles_path=./galaxy_roles
ansible-galaxy
will install roles by default into the first found path of roles_path
, so make sure to add the galaxy folder as very first if you have multiple role paths. You do not need to add the roles
folder explicitly. Ansible will by default always search for roles inside the ./roles
folder relative to the playbook.
Alternatively you can also instruct galaxy to install to a different location:
ansible-galaxy install --roles-path=./galaxy_roles foo
The @udonhan inheritance answer could be not enough if you have internal/custom roles that are not always relative to a playbook, I mean global roles.
You can manage multiple roles path in ansible.cfg file, so you can define an ansible.cfg file in your project path with:
[defaults]
roles_path = ./roles:./roles_internal
The "./roles" path can be used for ansible-galaxy roles, and the "./roles_internal" can be used for your internal/custom roles
Now when you execute
ansible-galaxy install -r requeriments.yml
Galaxy roles are installed in "./roles" by default
NOTE: You must be sure that ANSIBLE_ROLES_PATH env variable is not set or it will override the ansible.cfg settings. For testing:
unset ANSIBLE_ROLES_PATH