Hello friends.
Given a list of variables like this:
---
nginx_vhosts:
- {domain: "
thisisatest.com", usname: "thisisatest"}
- {domain: "
example.com", usname: "example"}
- {domain: "
company.com", usname: "company"}
assuming that all works fine in Jinja with:
....
{% for vhost in nginx_vhosts %}
server_name {{ vhost.domain }} www.{{ vhost.domain }};
root /home/{{ vhost.usname }}/public_html/;
{% endfor }
...
how to loop over nginx_vhosts.domain so task "template" can generate 1 file per domain? This task:
- name: Enable Vhost on CentOS OS family
template: src=templates/vhost-nginx.j2
dest=/etc/nginx/conf.d/{% for vhost in nginx_vhosts %}{{ vhost.domain }}.conf{% endfor %}
owner=root
group=root
mode=0644
give me: thisisatest.com.confexample.com.confcompany.com.conf
Already tried this but no luck, gives me 1 file per domain and all files have all vhosts.domain inside:
- name: Enable Vhost on CentOS OS family
template: src=templates/vhost-nginx.j2
dest=/etc/nginx/conf.d/{{ item.domain }}.conf
owner=root
group=root
mode=0644
with_item: nginx_vhosts
Thank you!