# "absolute" (root) include\_tasks path

**URL:** <https://forum.ansible.com/t/absolute-root-include-tasks-path/26903>\
**Category:** Ansible Project\
**Created:** [March 5, 2018, 10:08pm UTC](https://forum.ansible.com/t/absolute-root-include-tasks-path/26903 "2018-03-05T22:08:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josef\_Fortier](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@Josef\_Fortier](https://forum.ansible.com/u/Josef_Fortier)\
**Post date:** [March 5, 2018, 10:08pm UTC](https://forum.ansible.com/t/absolute-root-include-tasks-path/26903/1 "2018-03-05T22:08:44Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 5, 2018, 10:21pm UTC](https://forum.ansible.com/t/absolute-root-include-tasks-path/26903/2 "2018-03-05T22:21:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Josef\_Fortier](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@Josef\_Fortier](https://forum.ansible.com/u/Josef_Fortier)\
**Post date:** [March 5, 2018, 10:56pm UTC](https://forum.ansible.com/t/absolute-root-include-tasks-path/26903/3 "2018-03-05T22:56:17Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 6, 2018, 12:08am UTC](https://forum.ansible.com/t/absolute-root-include-tasks-path/26903/4 "2018-03-06T00:08:44Z")

</div>

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.
