# How to loop over variables so task "template" can generate 1 file per variable

**URL:** <https://forum.ansible.com/t/how-to-loop-over-variables-so-task-template-can-generate-1-file-per-variable/15117>\
**Category:** Ansible Project\
**Created:** [April 30, 2014, 1:15pm UTC](https://forum.ansible.com/t/how-to-loop-over-variables-so-task-template-can-generate-1-file-per-variable/15117 "2014-04-30T13:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Servermanaged](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Servermanaged](https://forum.ansible.com/u/Servermanaged)\
**Post date:** [April 30, 2014, 1:15pm UTC](https://forum.ansible.com/t/how-to-loop-over-variables-so-task-template-can-generate-1-file-per-variable/15117/1 "2014-04-30T13:15:16Z")

</div>

Hello friends.

Given a list of variables like this:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [April 30, 2014, 1:28pm UTC](https://forum.ansible.com/t/how-to-loop-over-variables-so-task-template-can-generate-1-file-per-variable/15117/2 "2014-04-30T13:28:02Z")

</div>

use 2nd option (with\_items: nginx\_vhosts) and use this template:

server\_name {{ item.domain }} www.{{ item.domain }};  
root /home/{{ item.usname }}/public\_html/;

​

---

<div class="post-metadata">

**Author:** ![Servermanaged](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Servermanaged](https://forum.ansible.com/u/Servermanaged)\
**Post date:** [April 30, 2014, 1:34pm UTC](https://forum.ansible.com/t/how-to-loop-over-variables-so-task-template-can-generate-1-file-per-variable/15117/3 "2014-04-30T13:34:43Z")

</div>

Thank you Brian! It worked!
