# While using j2 template and with\_items i get the last item in o/p

**URL:** <https://forum.ansible.com/t/while-using-j2-template-and-with-items-i-get-the-last-item-in-o-p/33122>\
**Category:** Ansible Project\
**Created:** [June 8, 2020, 5:20pm UTC](https://forum.ansible.com/t/while-using-j2-template-and-with-items-i-get-the-last-item-in-o-p/33122 "2020-06-08T17:20:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [June 8, 2020, 5:20pm UTC](https://forum.ansible.com/t/while-using-j2-template-and-with-items-i-get-the-last-item-in-o-p/33122/1 "2020-06-08T17:20:31Z")

</div>

Hi

my playbook is :

- name: include vars  
include\_vars:  
file: /home/rparida1/content-var.yml

- name: Testing  
template:  
src: /home/rparida1/config.j2  
dest: /home/rparida1/test-raka1111222.properties  
with\_items:

- “{{ Tenants }}”

When i use the with\_items, only the last item mentioned in my var file is displayed (my desired o/p is it should iterate through all the items mentioned in my var file):

iam.biz.tenant.auth.connetion.timeout=1000  
iam.biz.tenant.auth.response.timeout=1000  
iam.biz.tenant.auth.retry.count=3

iam.biz.tenant.auth.4231.host= test3  
iam.biz.tenant.auth.4231.authType=ldap1  
iam.biz.tenant.auth.4231.port=4433  
iam.biz.tenant.auth.4231.baseDN=ou=dfsd,ou=People21,[o=xxxxxx.com](http://o=xxxxxx.com)

I have a j2 template as follows:

iam.biz.tenant.auth.connetion.timeout={{ iam\_biz\_tenant\_auth\_connetion\_timeout | default(‘1000’) }}

iam.biz.tenant.auth.response.timeout={{ iam\_biz\_tenant\_auth\_response\_timeout | default(‘1000’) }}  
iam.biz.tenant.auth.retry.count={{ iam\_biz\_tenant\_auth\_retry\_count | default(‘3’) }}

iam.biz.tenant.auth.{{ item.Tenant\_ID }}.host= {{ item.Tenant\_host }}  
iam.biz.tenant.auth.{{ item.Tenant\_ID }}.authType={{ item.Tenant\_authType }}  
iam.biz.tenant.auth.{{ item.Tenant\_ID }}.port={{ item.Tenant\_port }}  
iam.biz.tenant.auth.{{ item.Tenant\_ID }}.baseDN={{ item.Tenant\_baseDN }}

my var file is as follows:

Tenants:

- {“Tenant\_ID”:“8888”, “Tenant\_host”:“test1”,“Tenant\_port”:“3333”, “Tenant\_authType”:“ldap1234”,“Tenant\_baseDN”:“ou=dfhsdjfsd,ou=People,[o=xxxxx.com](http://o=xxxxx.com)”}
- {“Tenant\_ID”:“7777”, “Tenant\_host”:“test7”,“Tenant\_port”:“7733”, “Tenant\_authType”:“ldap3777”,“Tenant\_baseDN”:“ou=7777,ou=People7,[o=xxxx.com](http://o=xxxx.com)”}
- {“Tenant\_ID”:“4231”, “Tenant\_host”:“test3”,“Tenant\_port”:“4433”, “Tenant\_authType”:“ldap1”,“Tenant\_baseDN”:“ou=dfsd,ou=People21,[o=xxxxxx.com](http://o=xxxxxx.com)”}

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 8, 2020, 6:25pm UTC](https://forum.ansible.com/t/while-using-j2-template-and-with-items-i-get-the-last-item-in-o-p/33122/2 "2020-06-08T18:25:14Z")

</div>

You are looping over the same template so that will only keep the last item.

Don’t loop over the template, but instead use a loop inside your template.
