"absolute" (root) include_tasks path

36 views
Skip to first unread message

Josef Fortier

unread,
Mar 5, 2018, 5:08:44 PM3/5/18
to Ansible Project
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.

Thanks :-)

Brian Coca

unread,
Mar 5, 2018, 5:21:47 PM3/5/18
to Ansible Project
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.


--
----------
Brian Coca

Josef Fortier

unread,
Mar 5, 2018, 5:56:17 PM3/5/18
to Ansible Project
Thanks Brian:

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 :-)

Brian Coca

unread,
Mar 5, 2018, 7:08:59 PM3/5/18
to Ansible Project
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.


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages