# Issues when using jinja "include" directive

**URL:** <https://forum.ansible.com/t/issues-when-using-jinja-include-directive/22426>\
**Category:** Ansible Developer\
**Created:** [August 30, 2016, 10:25pm UTC](https://forum.ansible.com/t/issues-when-using-jinja-include-directive/22426 "2016-08-30T22:25:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filipe\_Felisbino](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Filipe\_Felisbino](https://forum.ansible.com/u/Filipe_Felisbino)\
**Post date:** [August 30, 2016, 10:25pm UTC](https://forum.ansible.com/t/issues-when-using-jinja-include-directive/22426/1 "2016-08-30T22:25:51Z")

</div>

Hello

I was testing the latest devel version and one of my playbooks stopped working due to TemplateNotFound error on a jinja template. The problem is happening because my template includes another template ( {% include … %} ). The problem started on commit **3c39bb5633d0cbfa9cf22f9a4038296caef9c622**

To isolate the problem I’ve created a small role like:

(venv) ➜ cat roles/template/tasks/main.yml

- set\_fact: test=“{{ lookup(‘template’, ‘template1.j2’) }}”

- debug: var=test

(venv) ➜ cat roles/template/templates/template1.j2  
begin template 1  
{{ some\_value }}  
{% include ‘template2.j2’ %}  
end template 1

(venv) ➜ cat roles/template/templates/template2.j2  
begin template 2  
{{some\_value}}  
end template 2

(venv) ➜ cat test.yml

- hosts: localhost  
connection: local

roles:

- template

with the latest devel version, when I run that playbook I get:

(venv) ➜ ansible-include ansible-playbook test.yml -i localhost, -e some\_value=1000

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [template : set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TemplateNotFound: template2.j2  
fatal: [localhost]: FAILED! =\> {“failed”: true, “msg”: “Unexpected failure during module execution.”, “stdout”: “”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=1 changed=0 unreachable=0 failed=1

Then if I revert the template.py lookup to an older version it works:

(venv) ➜ ansible git:(test) ✗ git checkout 0bd6f3a5e8ff0c1534cc63e0f0bc8fef5f9dbf85 – lib/ansible/plugins/lookup/template.py

…

(venv) ➜ ansible-include ansible-playbook test.yml -i localhost, -e some\_value=1000

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [template : set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [template : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“test”: “begin template 1\n1000\nbegin template 2\n1000\nend template 2end template 1\n”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=3 changed=0 unreachable=0 failed=0
