Iterating over two tasks ?

42 views
Skip to first unread message

Vikas Kumar

unread,
May 14, 2015, 12:18:32 AM5/14/15
to ansible...@googlegroups.com
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

Vikas Kumar

unread,
May 14, 2015, 4:38:20 AM5/14/15
to ansible...@googlegroups.com
Hello Everyone,

I solved my issue using these two links.


Hope this helps someone who is facing the same problem.

Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages