# Iterating over two tasks ?

**URL:** <https://forum.ansible.com/t/iterating-over-two-tasks/18228>\
**Category:** Ansible Project\
**Created:** [May 14, 2015, 4:18am UTC](https://forum.ansible.com/t/iterating-over-two-tasks/18228 "2015-05-14T04:18:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikas\_Kumar](https://avatars.discourse-cdn.com/v4/letter/v/ecb155/32.png) [@Vikas\_Kumar](https://forum.ansible.com/u/Vikas_Kumar)\
**Post date:** [May 14, 2015, 4:18am UTC](https://forum.ansible.com/t/iterating-over-two-tasks/18228/1 "2015-05-14T04:18:32Z")

</div>

Hello All,

I have two tasks and few yaml files. This is obviously not working as all the files (/etc/nginx/myconfigs/{ab01a,ab01b,ab,www}) have variables from \*'\*\*www.\*_yml’,_ which is the last item in the iteration.

`

- include\_vars: site\_{{ item }}.yml  
with\_items: site\_files

- name: Create nginx files in /etc/nginx/myconfigs  
template: src=nginx\_site.d\_conf.j2 dest=/etc/nginx/myconfigs/{{ item }}.conf  
with\_items: site\_files  
`

These are the items in _‘site\_files’_ variable\*.\*  
`  
site\_files:

- ab01a
- ab01b
- ab
- www  
`

These are the yaml files in which I have few variables which I am substituting in the jinja2 template file (nginx\_site.d\_conf.j2).  
`  
ab01a.yml  
ab01b.yml  
ab.yml  
www.yml

`

Please help me to tackle this. I am looking out for a way to dynamically include variables from Yaml files and substitute those in template action.

I can do this by including one variable file and a template action at a time, but I am sure there would be a better way to handle this.

Regards,  
Vikas

---

<div class="post-metadata">

**Author:** ![Vikas\_Kumar](https://avatars.discourse-cdn.com/v4/letter/v/ecb155/32.png) [@Vikas\_Kumar](https://forum.ansible.com/u/Vikas_Kumar)\
**Post date:** [May 14, 2015, 8:38am UTC](https://forum.ansible.com/t/iterating-over-two-tasks/18228/2 "2015-05-14T08:38:20Z")

</div>

Hello Everyone,

I solved my issue using these two links.

[http://stackoverflow.com/questions/26606121/ansible-loop-over-variables](http://stackoverflow.com/questions/26606121/ansible-loop-over-variables)  
[http://tiku.io/questions/539822/how-to-loop-over-array-containing-template-variables-with-ansible](http://tiku.io/questions/539822/how-to-loop-over-array-containing-template-variables-with-ansible)

Hope this helps someone who is facing the same problem.

Regards,  
Vikas
