# Passing variables to template file in template module

**URL:** <https://forum.ansible.com/t/passing-variables-to-template-file-in-template-module/18727>\
**Category:** Ansible Project\
**Created:** [July 10, 2015, 3:37pm UTC](https://forum.ansible.com/t/passing-variables-to-template-file-in-template-module/18727 "2015-07-10T15:37:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Judeaux](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@Jeremy\_Judeaux](https://forum.ansible.com/u/Jeremy_Judeaux)\
**Post date:** [July 10, 2015, 3:37pm UTC](https://forum.ansible.com/t/passing-variables-to-template-file-in-template-module/18727/1 "2015-07-10T15:37:53Z")

</div>

Hi,

I have a template called in a loop. In order to improve readability and reusability, I’d like to avoid any {{item}}, {{item.0}} or {{item.1.something}} in my template file.

According to issue #4546, this doesn’t seem possible. There is no documentation about this on the template module page.  
I tried like the following, which is also not working:

- template: src=src.j2 dest=/tmp/dest  
vars:

index: “{{ item.0 }}”  
thing: “{{ item.1 }}”

with\_indexed\_items: things\_collection

Am I missing something ? Should I open a feature request for this ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 11, 2015, 2:18am UTC](https://forum.ansible.com/t/passing-variables-to-template-file-in-template-module/18727/2 "2015-07-11T02:18:48Z")

</div>

I'm not sure what you are asking for here, things\_collection is passed  
to your template as are all other vars defined in the play and for the  
host, there is no need to put it in with\_ if you just want to directly  
access the var already.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Judeaux](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@Jeremy\_Judeaux](https://forum.ansible.com/u/Jeremy_Judeaux)\
**Post date:** [July 13, 2015, 8:12am UTC](https://forum.ansible.com/t/passing-variables-to-template-file-in-template-module/18727/3 "2015-07-13T08:12:02Z")

</div>

I actually want one file per item in the collection, should have written the example this way:

- template:  
src: src.j2  
dest: “/tmp/dest-{{ item.0 }}”  
vars:  
index: “{{ item.0 }}”  
thing: “{{ item.1 }}”  
with\_indexed\_items: things\_collection
