Just looking for possible better approaches for specifying a semi absolute path to include_tasks.
I’ve come up with this:
vars:
pwd: ‘{{ lookup(“env”, “PWD”) }}’
And then constructing the include path with this variable (thus “rooting” the path to execution location).
Is there another way to construct an “absolute” (rooted) path (absolute to the top of the directory).
I’ve learned that ansible supports ‘ansible_search_path’ but that is set off of the originally loaded file.
Use case:
I have includes that include, and want to keep some path independence.
I want to have a completely self contained directory of files.
PWD is a bad option because it reflects 'directory in which user was
when he executed ansible-playbook', i.e `cd /var/tmp; ansible-playbook
~/work/secure/play.yml`
I would use playbook_dir or role_path as those are predictable
relative to the task definition or you can always define a 'project'
var and pass that when invoking the play.
For my purposes neither playbook_dir (is tied to the first directory, so doesn’t help for nested includes) or role_path (only works in roles) work.
But your advice is clearly sound, and you helped me find a choice that will work well for my purposes: inventory_dir
It’s grounded at the top of the source directory
That might work for your current setup, but be aware that if you have
multiple sources (possible >=2.4) hosts can have diff inventory_dir
depending on their location.