Hi,
I'm trying to create an Apache vhost config file using a legacy yaml file
*that I can't change*.
I'm nearly there, but the nested loop in the template doesn't work as
expected.
Here's the yaml:
sites:
site1.com:
vhosts:
- vhost1.com
- v <http://www.alpha.org/>host2.com
- v <http://brand2014.test.alpha.org/>host3.com
other1: blah
other2: blah
etc
etc
s <http://shop.alpha.org/>ite50.com:
vhosts:
- v <http://shop.alpha.org/>host51.com
- vhost52.com
- v <http://online.alpha.org/>host53.com
other1: blah
other2: blah
Here's my play:
- name: Populate vhost config
template: src=httpd.j2 dest=/etc/httpd/conf.d/vhosts.conf
with_dict: "{{ sites }}"
Here's my template:
<VirtualHost *>
{% for site in sites %}
ServerName {{ site }}
{% for vhost in item.value.vhosts %}
ServerAlias {{ vhost }}
{% endfor %}
DocumentRoot /var/www/html/{{ site }}
<Directory /var/www/html/{{ site }}
AllowOverride All
Order allow,deny
Allow from All
</Directory>
{% endfor %}
</Virtualhost>
Expected result:
<VirtualHost *>
ServerName site1.com
ServerAlias vhost1.com <http://vhost51.com/>
ServerAlias vhost2.com <http://vhost52.com/>
ServerAlias vhost3.com <http://vhost53.com/>
DocumentRoot /var/www/html/site1.com
<Directory /var/www/html/site1.com
AllowOverride All
Order allow,deny
Allow from All
</Directory>
etc
etc
ServerName site50.com
ServerAlias vhost51.com
ServerAlias vhost52.com
ServerAlias vhost53.com
DocumentRoot /var/www/html/site50.com
<Directory /var/www/html/site50.com
AllowOverride All
Order allow,deny
Allow from All
</Directory>
etc.
etc.
Actual result:
<VirtualHost *>
ServerName site1.com
ServerAlias vhost51.com
ServerAlias vhost52.com
ServerAlias vhost53.com
DocumentRoot /var/www/html/site1.com
<Directory /var/www/html/site1.com
AllowOverride All
Order allow,deny
Allow from All
</Directory>
etc
etc
ServerName site50.com
ServerAlias vhost51.com
ServerAlias vhost52.com
ServerAlias vhost53.com
DocumentRoot /var/www/html/site50.com
<Directory /var/www/html/site50.com
AllowOverride All
Order allow,deny
Allow from All
</Directory>
etc.
etc.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/413c8cc3-3983-4c59-b360-3fbb2de50a7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.