2019-05-10 23:07:18 +02:00
|
|
|
# nginx.snippet
|
2017-08-30 00:26:31 +02:00
|
|
|
#
|
|
|
|
# Manages creation of snippets
|
|
|
|
|
2019-05-16 08:27:21 +02:00
|
|
|
{%- set tplroot = tpldir.split('/')[0] %}
|
|
|
|
{%- from tplroot ~ '/map.jinja' import nginx, sls_block with context %}
|
|
|
|
{%- from tplroot ~ '/libtofs.jinja' import files_switch with context %}
|
2017-08-30 00:26:31 +02:00
|
|
|
|
2020-11-09 00:30:45 +01:00
|
|
|
{#- _nginx is a lightened copy of nginx map intended to passed in templates #}
|
|
|
|
{%- set _nginx = nginx.copy() %}
|
2021-01-23 15:04:12 +01:00
|
|
|
{%- do _nginx.pop('snippets') if nginx.snippets is defined %}
|
|
|
|
{%- do _nginx.pop('servers') if nginx.servers is defined %}
|
2020-11-09 00:30:45 +01:00
|
|
|
|
2017-08-30 00:26:31 +02:00
|
|
|
nginx_snippets_dir:
|
|
|
|
file.directory:
|
|
|
|
{{ sls_block(nginx.servers.dir_opts) }}
|
|
|
|
- name: {{ nginx.lookup.snippets_dir }}
|
|
|
|
|
|
|
|
{% for snippet, config in nginx.snippets.items() %}
|
|
|
|
nginx_snippet_{{ snippet }}:
|
|
|
|
file.managed:
|
2019-06-17 06:12:46 +02:00
|
|
|
- name: {{ nginx.lookup.snippets_dir ~ '/' ~ snippet }}
|
2019-05-16 08:27:21 +02:00
|
|
|
- source: {{ files_switch([ snippet, 'server.conf' ],
|
|
|
|
'nginx_snippet_file_managed'
|
|
|
|
)
|
|
|
|
}}
|
2017-08-30 00:26:31 +02:00
|
|
|
- template: jinja
|
|
|
|
- context:
|
|
|
|
config: {{ config|json() }}
|
2020-11-09 00:30:45 +01:00
|
|
|
nginx: {{ _nginx|json() }}
|
2020-09-23 21:05:07 +02:00
|
|
|
- require:
|
|
|
|
- file: nginx_snippets_dir
|
|
|
|
- require_in:
|
|
|
|
- file: nginx_config
|
2021-04-15 20:11:41 +02:00
|
|
|
- sls: nginx.servers
|
|
|
|
- sls: nginx.servers_config
|
2020-09-23 21:05:07 +02:00
|
|
|
- service: nginx_service
|
2017-08-30 00:26:31 +02:00
|
|
|
{% endfor %}
|