Iterating over two tasks ?

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

Hello Everyone,

I solved my issue using these two links.

http://stackoverflow.com/questions/26606121/ansible-loop-over-variables
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