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