Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep local roles separated from the ones loaded from ansible-galaxy?

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.

like image 704
sorin Avatar asked Jan 20 '16 13:01

sorin


People also ask

Where are ansible Galaxy roles stored?

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 .

Where can ansible Galaxy pull roles from?

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> .

Where are ansible system roles stored by default?

The default search path is ~/. ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles. in the directory where the playbook file is located.

How do I use multiple roles in ansible?

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.


1 Answers

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
like image 146
udondan Avatar answered Oct 30 '22 18:10

udondan