Does ansible have any mechanism for specifying a base directory for including things like variable files, playbooks, and tasks?
Here's my use case:
We keep our playbooks in a git repository called "ansible-playbooks". Anyone with admin privileges should be able to clone this repo and run the ansible playbooks. Because a git repo can be cloned to anywhere, we can't use absolute paths for things like vars_files and playbook includes. So we end up using relative paths, e.g. I have a playbook in ansible-playbooks/django/setup.yaml that has:
# Reconfigure nginx if needed
- include: ../nginx/setup.yaml
The problem with these relative includes is that they're brittle. If I move the ansible-playbooks/django/setup.yaml to ansible-playbooks/setup.yaml or ansible-playbooks/django/foo/setup.yaml, the relative include will break. I'd prefer to be able to do something like:
# Reconfigure nginx if needed
- include: $basedir/nginx/setup.yaml
This would also make it easier to find and replace import statemetns if I change the location of nginx/setup.yaml.
The problem is: how do I define basedir? I could make everyone write their own local.yaml file that contains something like:
basedir: /Users/lorin/ansible-playbooks
And then I'd include local.yaml in all of my plays:
vars_files:
- ../local.yaml
Is there a better way of doing this? In particular, is there a way to do this that would not require somebody editing a local.yaml file?
Take care,
Lorin