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.
By default, Ansible downloads roles to the first writable directory in the default list of paths ~/. ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles . This installs roles in the home directory of the user running ansible-galaxy .
Create roles with Ansible Galaxy Galaxy can use git to add other role sources, such as GitHub. You can initialize a new galaxy role using ansible-galaxy init , or you can install a role directly from the Ansible Galaxy role store by executing the command ansible-galaxy install <name of role> .
The default search path is ~/. ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles. in the directory where the playbook file is located.
Step 1 — Navigate to /etc/ansible/roles directory and create the roles for prerequisites, MongoDB and NodeJS. You should now see three roles in your 'roles' directory. Step 2 — Write main. yml for prerequisites which installs Git.
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:
roles
directory relative to your playbookansible.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With