# Why aren't template\_path and template\_fullpath expanded to different values?

**URL:** <https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788>\
**Category:** Ansible Project\
**Created:** [March 16, 2021, 10:00am UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788 "2021-03-16T10:00:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike2](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mike2](https://forum.ansible.com/u/mike2)\
**Post date:** [March 16, 2021, 10:00am UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/1 "2021-03-16T10:00:40Z")

</div>

> **[ansible.builtin.template module – Template a file out to a target host —...](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/template_module.html)**

says

- template\_path is the path of the template.

- template\_fullpath is the absolute path of the template.

Can someone explain how “the path” is suppose to be different from “the absolute path”? If I put both those variables in a template, they are expanded to the absolute path to the template on the source filesystem e.g.

# {{ template\_fullpath }}

# {{ template\_path }}

in a template results in this:

# /home/mike/gitrepos/ansibletesting/roles/foo/templates/blah.txt

# /home/mike/gitrepos/ansibletesting/roles/foo/templates/blah.txt

I’ve found a few other mentions of people saying the same thing, e.g. [Ansible template Module Tutorial + Examples | TopTechSkills.com](https://www.toptechskills.com/ansible-tutorials-courses/ansible-template-module-tutorial-examples/) says: “template\_fullpath - Same as template\_path in my experience” and in this old issue [GitHub · Where software is built](https://github.com/ansible/ansible/issues/29995) which seems to have gone nowhere someone says “There are two vars that play out to the same value.”.

I assume template\_path and template\_fullpath are supposed to be different values, but different how, and under what circumstances?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [March 16, 2021, 11:00am UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/2 "2021-03-16T11:00:15Z")

</div>

> [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html)  
> says  
> #
> 
> template\_path is the path of the template.
> 
> #
> 
> template\_fullpath is the absolute path of the template.
> 
> Can someone explain how "the path" is suppose to be different from "the absolute path"? If I put both those variables in  
> a template, they are expanded to the absolute path to the template on the source filesystem e.g.
> 
> # {{ template\_fullpath }}  
> # {{ template\_path }}
> 
> in a template results in this:
> 
> # /home/mike/gitrepos/ansibletesting/roles/foo/templates/blah.txt  
> # /home/mike/gitrepos/ansibletesting/roles/foo/templates/blah.txt
> 
> I've found a few other mentions of people saying the same thing, e.g.  
> [https://www.toptechskills.com/ansible-tutorials-courses/ansible-template-module-tutorial-examples/](https://www.toptechskills.com/ansible-tutorials-courses/ansible-template-module-tutorial-examples/) says:  
> "template\_fullpath - Same as template\_path in my experience" and in this old issue  
> [https://github.com/ansible/ansible/issues/29995](https://github.com/ansible/ansible/issues/29995) which seems to have gone nowhere someone says "There are two vars that  
> play out to the same value.".
> 
> I assume template\_path and template\_fullpath are supposed to be different values, but different how, and under what  
> circumstances?

Hello,

why did you need to know the template paths? What is your usecase for them?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<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 16, 2021, 1:38pm UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/3 "2021-03-16T13:38:56Z")

</div>

A bit of history here, initially path was the 'relative path' passed  
to src: for the template action and fullpath was the 'absolute  
resolved path' to the template file.

But later on a request for these same variables added to the template  
lookup created a change and moved them to a centralize function, but  
now that function receives only the resolved path (i consider this a  
bug) so they are always the same.

---

<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 16, 2021, 1:48pm UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/4 "2021-03-16T13:48:43Z")

</div>

This should fix the issue and show the correct value in all cases  
[https://github.com/ansible/ansible/pull/73924](https://github.com/ansible/ansible/pull/73924)

---

<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 16, 2021, 1:49pm UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/5 "2021-03-16T13:49:05Z")

</div>



---

<div class="post-metadata">

**Author:** ![mike2](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mike2](https://forum.ansible.com/u/mike2)\
**Post date:** [March 16, 2021, 2:57pm UTC](https://forum.ansible.com/t/why-arent-template-path-and-template-fullpath-expanded-to-different-values/34788/6 "2021-03-16T14:57:10Z")

</div>

Thanks, Brian, that was all very helpful. I look forward to the fix hitting release.

I’m looking at those variables because of the documented implications of the {file} part of ansible\_managed being absolute, what was said in [https://github.com/ansible/ansible/pull/15559](https://github.com/ansible/ansible/pull/15559) about ansible\_managed maybe being removed, and how much I like comments in files which explain which template was used to create them. Whilst looking at making my own variable to use in place of ansible\_managed I’ve come up with

{{ template\_fullpath | regex\_replace(‘^._/roles/(._)’,‘\1’) }}

which comes out as something like “foo/templates/blah.txt”. (Which is somewhat inelegant but the only way I could think of to deal with there being an unpredictable number of directories above the one called “roles”.)
