# Looping through a Template

**URL:** <https://forum.ansible.com/t/looping-through-a-template/24184>\
**Category:** Ansible Project\
**Created:** [April 10, 2017, 10:06pm UTC](https://forum.ansible.com/t/looping-through-a-template/24184 "2017-04-10T22:06:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Ward](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jeffrey\_Ward](https://forum.ansible.com/u/Jeffrey_Ward)\
**Post date:** [April 10, 2017, 10:06pm UTC](https://forum.ansible.com/t/looping-through-a-template/24184/1 "2017-04-10T22:06:51Z")

</div>

Hi,

I am new to ansible and new to the form.

I am wondering how to loop through a template

my template looks like this

{ item.sitename }}-test,{{ item.sitename }} description

and my variables look like this

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 11, 2017, 4:36pm UTC](https://forum.ansible.com/t/looping-through-a-template/24184/2 "2017-04-11T16:36:00Z")

</div>

Hi,

I think you are almost there.

You almost certainly don’t want to have ‘with\_items’ on your template call. This will try to template once for each item in “{{parameters}}”. But “{{parameters}}” is already a list of things, and is going to be available to use in the template as a list, so I think you just need to make your template like this

{% item for in parameters %}  
{ item.sitename }}-test,{{ item.sitename }} description  
{% endfor %}

That should loop through “{{parameters}}” and put each templated item onto a new line I think (not tested).

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Ward](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jeffrey\_Ward](https://forum.ansible.com/u/Jeffrey_Ward)\
**Post date:** [April 11, 2017, 6:06pm UTC](https://forum.ansible.com/t/looping-through-a-template/24184/3 "2017-04-11T18:06:08Z")

</div>

Jon I actually got it with this

{% for myitem in item.sitename|list %}

I left my Task the same with with items but changed my VAR to an array
