# Issue with template module

**URL:** <https://forum.ansible.com/t/issue-with-template-module/35745>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [September 16, 2021, 12:29pm UTC](https://forum.ansible.com/t/issue-with-template-module/35745 "2021-09-16T12:29:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [September 16, 2021, 12:29pm UTC](https://forum.ansible.com/t/issue-with-template-module/35745/1 "2021-09-16T12:29:08Z")

</div>

We have a playbook that uses a jinja2 template to prepare a report and email us. For some reason, the template module is failing. Here’s what I’m calling in my playbook:

- name: Prepare report  
template:  
src: templates/yum\_output.txt.j2  
dest: /tmp/yum\_output.txt  
connection: local  
run\_once: true

It tries to generate the report on the first host in our play, and fails as follows:

Failed to get information on remote file (/tmp/yum\_output.txt): /bin/sh: /usr/bin/python: No such file or directory

On that server, which is RHEL 7.9, python 2.7.5 is installed at /bin/python, and /usr/bin/python is symbolically linked to /usr/bin/python2, which is symbolically linked to /usr/bin/python2.7.

So why would this happen and how can we fix that?

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [September 17, 2021, 4:42am UTC](https://forum.ansible.com/t/issue-with-template-module/35745/2 "2021-09-17T04:42:20Z")

</div>

Use Verbose -vvv to see more details on error

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [September 20, 2021, 5:31pm UTC](https://forum.ansible.com/t/issue-with-template-module/35745/3 "2021-09-20T17:31:55Z")

</div>

I dont think the issue is with your remote RHEL79.  
But rather from the host you are running the play from.  
Because you are using “connection: local”, your localhost is responding on behalf of your remote.  
check the python path on your localhost; there are chances it doesnt have python2 but only python3.  
the question left is why does your ansible uses python2 as interpreter by default ? which version of ansible are you on ?  
Thx.

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [September 20, 2021, 7:35pm UTC](https://forum.ansible.com/t/issue-with-template-module/35745/4 "2021-09-20T19:35:24Z")

</div>

To be honest, we’re running this playbook out of Tower, so I’m not sure why its choosing the server it is to generate the report via the template module. Is there a way I can tell it to use the Ansible control node?

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [September 20, 2021, 9:39pm UTC](https://forum.ansible.com/t/issue-with-template-module/35745/5 "2021-09-20T21:39:36Z")

</div>

if the host you are running from is the control node, then a trick can consist in setting the python interpreter “wrongly”  
so in your inventory file, in front of your remote managed node (the rhel79 one), put this variable: ansible\_python\_interpreter=/usr/bin/python3 (or the location of python on your control node)  
But be aware: that way, you are deceiving the ansible engine 🙂 !  
but even with that, you may avoid the error but I am not sure you’ll get the expected results.  
The best way to approach it is to remove the “connection: local” directive, and if you need to run something locally, use the “delegate\_to: localhost” directive.
