# Loop over two lists variables in inventory file via jinja2 -- similar to zip() function in python

**URL:** <https://forum.ansible.com/t/loop-over-two-lists-variables-in-inventory-file-via-jinja2-similar-to-zip-function-in-python/29709>\
**Category:** Ansible Project\
**Created:** [February 19, 2019, 5:32pm UTC](https://forum.ansible.com/t/loop-over-two-lists-variables-in-inventory-file-via-jinja2-similar-to-zip-function-in-python/29709 "2019-02-19T17:32:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahitansar](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@sahitansar](https://forum.ansible.com/u/sahitansar)\
**Post date:** [February 19, 2019, 5:32pm UTC](https://forum.ansible.com/t/loop-over-two-lists-variables-in-inventory-file-via-jinja2-similar-to-zip-function-in-python/29709/1 "2019-02-19T17:32:36Z")

</div>

my inventory file is like below with more additional group\_vars and host\_vars that I havent mentioned here for simplicity:  
I dont want to use host\_vars as of now.

[qa]  
host1 var1=‘[“hi” , “xy”]’ var2=[435345, 3425634]  
host1 var2=‘[“asd” , “er”]’ var2=[212, 456]

host1 var3=‘[“zxc” , “ghhj”]’ var2=[567, 80]

host1 var4=‘[“hi” , “hhj”]’ var2=[435, 980]

Im trying to create a yml file out of this via jinja2

{{% for host in groups[‘qa’] %}}  
host: {{ host }}  
params:  
{{% for i,j in zip(var1,var2) %}} → Im not sure how to achieve something like this in jinja2. Can someone please guide?  
app: {{ i }  
port: {{ j }}

---

<div class="post-metadata">

**Author:** ![sahitansar](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@sahitansar](https://forum.ansible.com/u/sahitansar)\
**Post date:** [February 19, 2019, 5:54pm UTC](https://forum.ansible.com/t/loop-over-two-lists-variables-in-inventory-file-via-jinja2-similar-to-zip-function-in-python/29709/2 "2019-02-19T17:54:30Z")

</div>

Just to add/explain more.

The jinja2 template with create an yaml with two stanzas per host, with first stanza containing first value of var1 n var2

And second stanza with second value of var1 n var2.

So entire yaml generated in this way will have two stanza per host

---

<div class="post-metadata">

**Author:** ![sahitansar](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@sahitansar](https://forum.ansible.com/u/sahitansar)\
**Post date:** [February 19, 2019, 6:03pm UTC](https://forum.ansible.com/t/loop-over-two-lists-variables-in-inventory-file-via-jinja2-similar-to-zip-function-in-python/29709/3 "2019-02-19T18:03:59Z")

</div>

Just to add/explain more.

The jinja2 template should create an yaml with two stanzas per host, with first stanza containing first value of var1 n var2

And second stanza with second value of var1 n var2.

So entire yaml generated in this way will have two stanza per host
