Feature Poll: Configuration option 'additional_roles_path' for common roles

In my usage of roles, I’ve found that I have a collection of project specific roles (db server, deploy webapp, etc) and another class of more common, shared roles (install via tarball, sync through git, etc).

In a given project I want to include both. I have a few choices for how to make this happen:

  1. Bundle the common roles with the project in a place ansible automatically looks
  2. Reference the roles by path, whether absolute or relative.

My use case is such that I create common roles for a larger development floor, then they become something like end-users who want this stuff to work like a black box.

The first option, bundling, can be made possible with symlinks or git submodules, but in we don’t use git, so submodules are out, and managing symlinks across environments is a bear to maintain, especially across distributed teams.

Because of this I opted for a single repository containing the common roles and a simple bash script that forwards ansible some simple configuration.

I end up using this pattern a lot, and I think the -e flag is a wonderful and flexible feature. It has let me bend ansible to my crazy needs on more than one occasion.

– configured-ansible-playbook.sh
#!/bin/bash
source role_finder.sh
exec ansible-playbook -e common_roles=find_common_roles_path $@

Then, when you want to use a role you wind up saying:

roles:

  • “{{ common_roles }}”/tarball-installer

And no matter where one of our developers project is ansible is able to find the common role. Alternatively, they can provide their own path to common roles by providing another -e flag.

While this works, I wish I didn’t have the extra step of ‘install my ansible wrapper’ when I tell our devs how to use ansible.

What would make my particular use case (common, project independent roles) more convenient is to have an environment variable / .ansible.cfg option called something along the lines of additional_roles_path that will search for roles in the provided directories after exhausting the directories it already searches in.

It might look something like this:

[defaults]
hostfile = /home/thomas/projects/config/ansible-common/scripts/host
library = /home/thomas/projects/config/ansible-common/library:/usr/share/ansible


roles_path = /home/thomas/projects/config/ansible-common/roles:/home/thomas/projects/config/ansible-third-party/roles

Thoughts?

– Thomas Omans

I’ll accept a roles path, if it does the following:

(A) there is no additional CLI option (it should have an environment option though)
(B) playbook roles paths continue to be searched as is and this is a fallback path to be used when not found in the other locations.
(C) it works as follows:

roles:

  • { role: foo }

And you don’t have to use the variable like “role_path” anywhere.

Not sure what the social conventions are / will be concerning “polls” on ansible-devel, but…

+1

Regards,
Joost