Last Updated: February 25, 2016
·
2.147K
· Lorin Hochstein

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

4 Responses
Add your response

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 ·