Why aren't template_path and template_fullpath expanded to different values?

22 views
Skip to first unread message

mike _

unread,
Mar 16, 2021, 6:00:40 AM3/16/21
to Ansible Project
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/ says: "template_fullpath - Same as template_path in my experience" and in this old issue 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?

Stefan Hornburg (Racke)

unread,
Mar 16, 2021, 7:00:42 AM3/16/21
to ansible...@googlegroups.com
On 3/16/21 11:00 AM, mike _ wrote:
> 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/ says:
> "template_fullpath - Same as template_path in my experience" and in this old issue
> 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
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/18685559-0a32-4c3a-a69d-2613ead38a2en%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/18685559-0a32-4c3a-a69d-2613ead38a2en%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Brian Coca

unread,
Mar 16, 2021, 9:39:29 AM3/16/21
to Ansible Project
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.

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

Brian Coca

unread,
Mar 16, 2021, 9:49:15 AM3/16/21
to Ansible Project
This should fix the issue and show the correct value in all cases
https://github.com/ansible/ansible/pull/73924


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

Brian Coca

unread,
Mar 16, 2021, 9:49:44 AM3/16/21
to Ansible Project
--
----------
Brian Coca

mike _

unread,
Mar 16, 2021, 10:57:10 AM3/16/21
to Ansible Project
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 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".)


Reply all
Reply to author
Forward
0 new messages