- group: {{ nginx.server.config.user }} | - group: {{ nginx.server.config.user }} | ||||
{% endif %} | {% endif %} | ||||
{% if 'source' in nginx.server.config %} | |||||
{% set source_path = nginx.server.config.source %} | |||||
{% else %} | |||||
{% set source_path = 'salt://nginx/ng/files/nginx.conf' %} | |||||
{% endif %} | |||||
nginx_config: | nginx_config: | ||||
file.managed: | file.managed: | ||||
{{ sls_block(nginx.server.opts) }} | {{ sls_block(nginx.server.opts) }} | ||||
- name: {{ nginx.lookup.conf_file }} | - name: {{ nginx.lookup.conf_file }} | ||||
- source: salt://nginx/ng/files/nginx.conf | |||||
- source: {{ source_path }} | |||||
- template: jinja | - template: jinja | ||||
{% if 'source' not in nginx.server.config %} | |||||
- context: | - context: | ||||
config: {{ nginx.server.config|json() }} | config: {{ nginx.server.config|json() }} | ||||
{% endif %} |
# Managed enabled/disabled state for servers | # Managed enabled/disabled state for servers | ||||
{% for server, settings in nginx.servers.managed.items() %} | {% for server, settings in nginx.servers.managed.items() %} | ||||
{% if settings.config != None %} | {% if settings.config != None %} | ||||
{% if 'source' in settings.config %} | |||||
{% set source_path = settings.config.source %} | |||||
{% else %} | |||||
{% set source_path = 'salt://nginx/ng/files/server.conf' %} | |||||
{% endif %} | |||||
{% set conf_state_id = 'server_conf_' ~ loop.index0 %} | {% set conf_state_id = 'server_conf_' ~ loop.index0 %} | ||||
{{ conf_state_id }}: | {{ conf_state_id }}: | ||||
file.managed: | file.managed: | ||||
{{ sls_block(nginx.servers.managed_opts) }} | {{ sls_block(nginx.servers.managed_opts) }} | ||||
- name: {{ server_curpath(server) }} | - name: {{ server_curpath(server) }} | ||||
- source: salt://nginx/ng/files/server.conf | |||||
- source: {{ source_path }} | |||||
- template: jinja | - template: jinja | ||||
{% if 'source' not in settings.config %} | |||||
- context: | - context: | ||||
config: {{ settings.config|json() }} | config: {{ settings.config|json() }} | ||||
{% endif %} | |||||
{% if 'overwrite' in settings and settings.overwrite == False %} | {% if 'overwrite' in settings and settings.overwrite == False %} | ||||
- unless: | - unless: | ||||
- test -e {{ server_curpath(server) }} | - test -e {{ server_curpath(server) }} |
# 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: | ||||
source: salt://path_to_nginx_conf_file/nginx.conf # IMPORTANT: This option is mutually exclusive with the rest of the | |||||
# options; if it is found other options (worker_processes: 4 and so | |||||
# on) are not processed and just upload the file from source | |||||
worker_processes: 4 | worker_processes: 4 | ||||
pid: /var/run/nginx.pid ### Directory location must exist | pid: /var/run/nginx.pid ### Directory location must exist | ||||
events: | events: | ||||
# test something else; | # test something else; | ||||
# } | # } | ||||
# } | # } | ||||
mysite2: # Using source options to upload the file instead of templating all the file | |||||
enabled: True | |||||
available_dir: /etc/nginx/sites-available | |||||
enabled_dir: /etc/nginx/sites-enabled | |||||
config: | |||||
source: salt://path-to-site-file/mysite2 | |||||
certificates_path: '/etc/nginx/ssl' # Use this if you need to deploy below certificates in a custom path. | certificates_path: '/etc/nginx/ssl' # Use this if you need to deploy below certificates in a custom path. | ||||
# If you're doing SSL termination, you can deploy certificates this way. | # If you're doing SSL termination, you can deploy certificates this way. |