Dear list,
one thing that is really nice about Ansible is how the playbook
becomes the centre of execution, and if you run
ansible-playbook /path/to/my/playbook
then that directory is where Ansible will also look for templates
required in the tasks of this playbook. Apparently, you can also now
define group_vars/host_vars next to the playbook, so it's a big step
towards self-containment.
Enter roles, reusable stuff to be used from playbooks. Roles are
looked for in the subdirectory roles/ in the parent directory of the
playbook, or you can specify a relative path to the directory of
another playbook, or you can specify an absolute path to a role
directory per se.
Now, what is the best approach if I want to use the same role from
both, playbook1/foo.yml and playbook2/bar.yml?
I'd like to avoid hard-coding absolute paths, as people clone from
Git to their own locations;
I don't even want to assume that playbook1 and playbook2 are in the
same place on the filesystem;
And I'd rather not put one copy of a role into playbook1/ and
another copy into playbook2/.
Is there another way?
If not, I could imagine two solutions:
1. if a role is not found in the usual location, see if a roles/
directory next to the inventory has it;
2. provide a configuration option and maybe environment variable
with which to specify a roles search path. This would be
especially useful if distros started providing roles somewhere
in /usr/share, encouraging people to use them.
The two options can also obviously be combined.
What do you think?