Sunday, February 23, 2014

Git Submodules for Ansible Roles

Not totally sure this is the right way to do it, but here is what I want to achieve, and how I do it:

For different apps I want to use Ansible for setup/deployment, using my own roles, and I want to re-use those roles between apps. I could have everything in one directory tree (living in git for version control), but that means keeping deployment configuration for all apps in a single repo; I would rather like to have those configurations separated.

I couldn't find any authoritative info on how to do this, so here's my approach.

  • Every role lives in its own git repo. An example is Vincent Rischmann's ansible-role-java.
  • Every app (or project) has its own git repo for its Ansible configuration (inventory definition and playbooks etc.).
  • The app repo has a roles sub directory. Actual roles (e.g. the java role) are then added as git submodules.

git submodule add https://github.com/vrischmann/ansible-role-java.git roles/java

and, voilá, Vincent's role is now available as a role 'java' in my project's Ansible configuration.


6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Chris,

    This sounds like the right way to go. Did you get any useful comments?

    ReplyDelete
  3. The author of this article seems to agree with your approach at least: https://www.theodo.fr/blog/2015/10/best-practices-to-build-great-ansible-playbooks/

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Seth DaemenDecember 19, 2018 at 4:45 AM
    submodules was my idea also but it seems not to work with awx/tower

    ReplyDelete