# Error in huge template - how to find the culprit?

**URL:** <https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663>\
**Category:** Ansible Project\
**Created:** [January 25, 2024, 2:08pm UTC](https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663 "2024-01-25T14:08:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 25, 2024, 2:08pm UTC](https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663/1 "2024-01-25T14:08:14Z")

</div>

Hii,

I have a template that has a lot of variables and control structures. I get an error during the playbook run:

fatal: [prod\_nagios2]: FAILED! =\> changed=false  
msg: |-  
AnsibleError: Unexpected templating type error occurred on (

): ‘NoneType’ object is not iterable

The content of the template is 800 lines, about 36kB, with 100+ variables.  
Anyone have an idea where to start looking?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 25, 2024, 3:36pm UTC](https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663/2 "2024-01-25T15:36:13Z")

</div>

with extra debugging:

The full traceback is:  
Traceback (most recent call last):  
File “/Users/dick.visser/foo/venv/lib/python3.11/site-packages/ansible/template/ **init**.py”, line 1160, in do\_template  
res = j2\_concat(rf)  
^^^^^^^^^^^^^  
File “”, line 764, in root  
TypeError: ‘NoneType’ object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File “/Users/dick.visser/foo/venv/lib/python3.11/site-packages/ansible/plugins/action/template.py”, line 150, in run  
resultant = templar.do\_template(template\_data, preserve\_trailing\_newlines=True, escape\_backslashes=False)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Users/dick.visser/foo/venv/lib/python3.11/site-packages/ansible/template/ **init**.py”, line 1171, in do\_template  
raise AnsibleError(“Unexpected templating type error occurred on (%s): %s” % (to\_native(data), to\_native(te)))  
ansible.errors.AnsibleError: Unexpected templating type error occurred on (

I guessed that “line 764” would be the location in the template, but at that place nothing seems relevant…

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 25, 2024, 4:05pm UTC](https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663/3 "2024-01-25T16:05:52Z")

</div>

Line 764 in root is referencing the python code that jinja ultimately generates to run. So there isn’t really an easy way to map that back to the template itself.

I have a tool that can ingest a jinja template, and print out that python code. It’s possible you might be able to visually understand what the python code is doing, and trace that back to a line in your jinja template. You can find it at:

[https://gist.github.com/sivel/6c93326b4cadd127bceb9ca6bb7e204a](https://gist.github.com/sivel/6c93326b4cadd127bceb9ca6bb7e204a)

Run like: python j2generated.py \< template.j2

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 25, 2024, 6:37pm UTC](https://forum.ansible.com/t/error-in-huge-template-how-to-find-the-culprit/38663/4 "2024-01-25T18:37:49Z")

</div>

thx, but that failed on missing filters.  
In any case, I stripped out al for loops and found the problem.  
The deployer had commented out list items, but did not leave any.  
So:

foobar:

- bar
- baz
- bor

was in the config as:

foobar:

# - bar

# - baz

# - bor

which meant it wasn’t a list anymore, but null instead, and thus None in python…

Dick
