# Jinja2 template loop with JSON

**URL:** <https://forum.ansible.com/t/jinja2-template-loop-with-json/32201>\
**Category:** Ansible Project\
**Created:** [February 11, 2020, 12:14pm UTC](https://forum.ansible.com/t/jinja2-template-loop-with-json/32201 "2020-02-11T12:14:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juergen\_Hofer](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Juergen\_Hofer](https://forum.ansible.com/u/Juergen_Hofer)\
**Post date:** [February 11, 2020, 12:14pm UTC](https://forum.ansible.com/t/jinja2-template-loop-with-json/32201/1 "2020-02-11T12:14:05Z")

</div>

Hello all,

I am a Network Engineer and Ansible is relative new for me.

At the moment I am trying to build a template with “JSON” as source. See below.

The template should do the follwing (hopefully you get the idea).  
I am struggling, how can i get the items in the list “INT\_LIST” ?  
Can someone point my to a good sample or documentation.

TIA  
Juergen

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 11, 2020, 12:22pm UTC](https://forum.ansible.com/t/jinja2-template-loop-with-json/32201/2 "2020-02-11T12:22:45Z")

</div>

> Hello all,
> 
> I am a Network Engineer and Ansible is relative new for me.
> 
> At the moment I am trying to build a template with "JSON" as source. See below.
> 
> The template should do the follwing (hopefully you get the idea).  
> I am struggling, how can i get the items in the list "INT\_LIST" ?  
> Can someone point my to a good sample or documentation.
> 
> TIA  
> Juergen

Hello Juergen,

this should do the trick:

{% for item in host.INT\_LIST %}

I suggest to pick a different loop variable name as "item" is the standard one  
in Jinja.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Juergen\_Hofer](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Juergen\_Hofer](https://forum.ansible.com/u/Juergen_Hofer)\
**Post date:** [February 11, 2020, 12:45pm UTC](https://forum.ansible.com/t/jinja2-template-loop-with-json/32201/3 "2020-02-11T12:45:50Z")

</div>

> Hello Juergen,
> 
> this should do the trick:
> 
> {% for item in host.INT\_LIST %}
> 
> I suggest to pick a different loop variable name as “item” is the standard one  
> in Jinja.
> 
> Regards  
> Racke

Hello Racke,

this was the missing part. 🙂

Thank you so much!  
Regards from Switzerland  
Juergen
