Recently I wrote about how to get started with ansible. Meanwhile continue working with ansible and recently started a second project that uses ansible as well and suddenly I realized that some roles look very similar and could be reused. This is easy if your roles are small and do one thing but do it well (UNIX style).

public role aholbreich.maven

aholbreich.maven - is my first public role. That role installs maven on your machine. For now, I have chosen not to wire it to any java role as a dependency. Just keep in mind maven needs java of course.

Now, this role can be installed and used on every ansible control machine I need.

ansible-galaxy install aholbreich.maven 

installs that maven role. And here is the usage example in a playbook.

- hosts: jenkins
  roles:
    - { role: aholbreich.maven }

If no variables (re)defined, maven version 3.3.9 will be installed and configured.

Dependencies list

If the project grows your list of installed modules grows as well, so you want to track and install them together.

Likely you can do it by having a dependency list e.g requirements.yml looking like this:

 - src: aholbreich.maven
 - src: aholbreich.java
...

and install all listed dependencies at once.

ansible-galaxy install -r requirements.yml

Bur there is even more… For example, you can install dependencies from different sources like GitHub, bitbucket, and file systems directly. This is a really powerful concept, so think about sharing roles and reuse existing ones.

Hope this encourages someone you to use galaxy too. Feel free to give your feedback here or on github