i have a state to manage nginx conf files where i use a for loop to cycle through a pillar value, applying jinja templates to each managed config file. i am having trouble with passing the variable from the for loop in the state file into the jinja template.
pillar value:
--snip
--snip
nginx.sls:
--snip
{% for nginx_site in pillar['nginx_sites'], %}
/etc/nginx/sites-enabled/{{ nginx_site }}.conf:
file.managed:
- template: jinja
- source: salt://environments/prod/web/location1/files/nginx.conf.jinja
- user: root
- group: root
- mode: 644
- require:
- pkg: nginx-full
{% endfor %}
--snip
jinja template:
--snip
server {
listen 443;
server_name {{ nginx_site }} *.{{ nginx_site }}
ssl on;
ssl_certificate /etc/nginx/ssl/wildcard.{{ nginx_site }}.chained.crt;
ssl_certificate_key /etc/nginx/ssl/{{ nginx_site }}.key;
if ($request_uri !~ ^/(wp-|order-page))
{
rewrite ^ http://$host$request_uri? permanent;
}
location / {
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /nginx_status {
stub_status on;
access_log off;
allow all;
deny all;
}
}
--snip
salt-call output:
--snip
State: - file
Name: /etc/nginx/sites-enabled/testdomain1.com.conf
Function: managed
Result: False
Comment: Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/salt/utils/templates.py", line 99, in jinja
data = template.render(**passthrough)
File "/usr/lib/pymodules/python2.6/jinja2/environment.py", line 891, in render
return self.environment.handle_exception(exc_info, True)
File "/var/cache/salt/files/base/environments/prod/web/location1/files/nginx.conf.jinja", line 7, in top-level template code
ssl_certificate_key /etc/nginx/ssl/{{ nginx_site }}.key;
UndefinedError: 'nginx_site' is undefined
--snip
is there a way to pass the value of "nginx_site" to the jinja template? could this be done with a context setting or something?
thanks in advance