Specify a base directory
If your ansible playbooks live in a git repository, you can use this trick to specify a base directory for resolving your includes:
Add the following line to <INVENTORY_FILE_LOCATION>/group_vars/all
:
base: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
Now you can do includes like this:
- include: {{ base }}/nginx/setup.yaml
Written by Lorin Hochstein
Related protips
4 Responses

Might want to use a local play and register it instead, just as that will execute a few too many times if used a lot... we need to get the "PIPE_ONCE" part going.
over 1 year ago
·

If I just change that from PIPE to PIPE_ONCE, will that do the trick?
over 1 year ago
·

New syntax for ansible using jinja:
base: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
over 1 year ago
·

@gblahaerath Thanks, I updated the tip accordingly.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors

tartansandal
73.35K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#