Finishes vhost config template

This commit is contained in:
Chad Heuschober 2014-05-19 13:04:43 -04:00
parent 81de880fe0
commit 825bd7950e
4 changed files with 105 additions and 48 deletions

View File

@ -0,0 +1,29 @@
{% set ind_increment = 4 %}
{%- macro vhost_config(values, key='', ind=0, lb='\n', delim=';', operator=' ') -%}
{%- for value in values -%}
{%- if value is number or value is string -%}
{{ lb }}{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}
{%- elif value is mapping -%}
{%- for k, v in value.items() -%}
{%- if v is number or v is string -%}
{{ vhost_config([v], k, ind) }}
{%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%}
{{ lb }}{{ k|indent(ind,True) }}{{ vhost_config(v,'', 0, '', '')}}{{ delim }}
{%- else %}
{{ k|indent(ind, True) }} {{ '{' }}
{{- vhost_config(v, '', ind + ind_increment) }}
{{ '}'|indent(ind, True) }}
{%- endif -%}
{%- endfor -%}
{%- elif value is iterable -%}
{{ vhost_config(value, ind + ind_increment, delim, operator) }}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
# Nginx vhost configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.
{{ vhost_config(config) }}

View File

@ -68,8 +68,7 @@
'dir_opts': { 'dir_opts': {
'makedirs': True, 'makedirs': True,
}, },
'managed': {} 'managed': {},
},
}, },
}, merge=True) %} }, merge=True) %}

View File

@ -92,7 +92,7 @@ nginx_vhost_available_dir:
- source: salt://nginx/ng/files/vhost.conf - source: salt://nginx/ng/files/vhost.conf
- template: jinja - template: jinja
- context: - context:
config: settings.config config: {{ settings.config }}
{% do vhost_states.append(conf_state_id) %} {% do vhost_states.append(conf_state_id) %}
{% endif %} {% endif %}

View File

@ -13,55 +13,84 @@ nginx:
# ======== # ========
nginx: nginx:
# These are usually set by grains in map.jinja ng:
lookup: # These are usually set by grains in map.jinja
package: nginx-custom lookup:
service: nginx package: nginx-custom
webuser: www-data service: nginx
conf_file: /etc/nginx/nginx.conf webuser: www-data
vhost_available: /etc/nginx/sites-available conf_file: /etc/nginx/nginx.conf
vhost_enabled: /etc/nginx/sites-enabled vhost_available: /etc/nginx/sites-available
vhost_use_symlink: True vhost_enabled: /etc/nginx/sites-enabled
vhost_use_symlink: True
# Source compilation is not currently a part of nginx.ng # Source compilation is not currently a part of nginx.ng
from_source: False from_source: False
package: package:
opts: {} # this partially exposes parameters of pkg.installed opts: {} # this partially exposes parameters of pkg.installed
service: service:
enable: True # Whether or not the service will be enabled/running or dead enable: True # Whether or not the service will be enabled/running or dead
opts: {} # this partially exposes parameters of service.running / service.dead opts: {} # this partially exposes parameters of service.running / service.dead
server: server:
opts: {} # this partially exposes file.managed parameters as they relate to the main nginx.conf file opts: {} # this partially exposes file.managed parameters as they relate to the main nginx.conf file
# nginx.conf (main server) declarations # nginx.conf (main server) declarations
# dictionaries map to blocks {} and lists cause the same declaration to repeat with different values # dictionaries map to blocks {} and lists cause the same declaration to repeat with different values
config: config:
worker_processes: 4 worker_processes: 4
pid: /run/nginx.pid pid: /run/nginx.pid
events: events:
worker_connections: 768 worker_connections: 768
http: http:
sendfile: on sendfile: on
include: include:
- /etc/nginx/mime.types - /etc/nginx/mime.types
- /etc/nginx/conf.d/*.conf - /etc/nginx/conf.d/*.conf
vhosts: vhosts:
disabled_postfix: .disabled # a postfix appended to files when doing non-symlink disabling disabled_postfix: .disabled # a postfix appended to files when doing non-symlink disabling
symlink_opts: {} # partially exposes file.symlink params when symlinking enabled sites symlink_opts: {} # partially exposes file.symlink params when symlinking enabled sites
rename_opts: {} # partially exposes file.rename params when not symlinking disabled/enabled sites rename_opts: {} # partially exposes file.rename params when not symlinking disabled/enabled sites
managed_opts: {} # partially exposes file.managed params for managed vhost files managed_opts: {} # partially exposes file.managed params for managed vhost files
dir_opts: {} # partially exposes file.directory params for site available/enabled dirs dir_opts: {} # partially exposes file.directory params for site available/enabled dirs
# vhost declarations # vhost declarations
# vhosts will default to being placed in vhost_available # vhosts will default to being placed in vhost_available
managed: managed:
mysite: # relative pathname of the vhost file mysite: # relative pathname of the vhost file
# may be True, False, or None where True is enabled, False, disabled, and None indicates no action # may be True, False, or None where True is enabled, False, disabled, and None indicates no action
dir: /tmp # an alternate directory (not sites-available) where this vhost may be found dir: /tmp # an alternate directory (not sites-available) where this vhost may be found
disabled_name: mysite.aint_on # an alternative disabled name to be use when not symlinking disabled_name: mysite.aint_on # an alternative disabled name to be use when not symlinking
enabled: True enabled: True
config: [] # May be a list or None, if None, no vhost file will be managed/templated
# May be a list of config options or None, if None, no vhost file will be managed/templated
# Take server directives as lists of dictionaries. If the dictionary value is another list of
# dictionaries a block {} will be started with the dictionary key name
config:
- server:
- server_name: localhost
- listen:
- 80
- default_server
- index:
- index.html
- index.htm
- location ~ .htm:
- try_files:
- $uri
- $uri/ =404
- test: something else
# The above outputs:
# server {
# server_name localhost;
# listen 80 default_server;
# index index.html index.htm;
# location ~ .htm {
# try_files $uri $uri/ =404;
# test something else;
# }
# }