Skip to content

Commit 8035f4b

Browse files
author
sticky-note
committed
feat(servers_config): passes context to custom source_path templates
1 parent 982705f commit 8035f4b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

nginx/config.sls

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ nginx_config:
2020
- name: {{ nginx.lookup.conf_file }}
2121
- source:
2222
{% if 'source_path' in nginx.server.config %}
23-
- {{ nginx.server.config.source_path }}
23+
- {{ nginx.server.config.pop('source_path') }}
2424
{% endif %}
2525
{{ files_switch(['nginx.conf'],
2626
'nginx_config_file_managed'
2727
)
2828
}}
2929
- template: jinja
30-
{% if 'source_path' not in nginx.server.config %}
3130
- context:
32-
config: {{ nginx.server.config|json(sort_keys=False) }}
33-
{% endif %}
31+
config: {{ nginx.server.get('config', {})|json(sort_keys=False) }}

nginx/servers_config.sls

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ nginx_server_available_dir:
115115
- name: {{ server_curpath(server) }}
116116
- source:
117117
{%- if 'source_path' in settings.config %}
118-
- {{ settings.config.source_path }}
118+
- {{ settings.config.pop('source_path') }}
119119
{%- endif %}
120120
{{ files_switch([server, 'server.conf'],
121121
'server_conf_file_managed'
@@ -129,11 +129,9 @@ nginx_server_available_dir:
129129
- {{ k }}: {{ v }}
130130
{%- endfor %}
131131
{%- endif %}
132-
{% if 'source_path' not in settings.config %}
133132
- context:
134-
config: {{ settings.config|json(sort_keys=False) }}
135133
nginx: {{ _nginx|json() }}
136-
{% endif %}
134+
config: {{ settings.get('config',{})|json(sort_keys=False) }}
137135
{% if 'overwrite' in settings and settings.overwrite == False %}
138136
- unless:
139137
- test -e {{ server_curpath(server) }}

pillar.example

+11-5
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ nginx:
119119
## - - -- - - -- -- - - --- -- - -- - - - -- - - - - -- - - - -- - - - -- - ##
120120
config:
121121
include: 'snippets/letsencrypt.conf'
122-
# IMPORTANT: This option is mutually exclusive with TOFS and the rest of
123-
# the options; if it is found other options (worker_processes: 4 and so
124-
# on) are not processed and just upload the file from source
122+
# IMPORTANT: This option is mutually exclusive with TOFS.
123+
# It uploads the file from source and passes the global `nginx` and the
124+
# `config` dictionnary to the template (without the `source_path` key).
125+
# `jinja` is assumed as template type.
125126
source_path: salt://path_to_nginx_conf_file/nginx.conf
126127
worker_processes: 4
127128
# pass as very first in configuration; otherwise nginx will fail to start
@@ -278,9 +279,14 @@ nginx:
278279
available_dir: /etc/nginx/sites-available
279280
enabled_dir: /etc/nginx/sites-enabled
280281
config:
281-
# IMPORTANT: This field is mutually exclusive with TOFS and other
282-
# config options, it just uploads the specified file
282+
# IMPORTANT: This field is mutually exclusive with TOFS.
283+
# It uploads the file from source and passes the global `nginx` and the
284+
# `config` dictionnary to the template (without the `source_path` key).
285+
# `jinja` is assumed as template type.
283286
source_path: salt://path-to-site-file/mysite2
287+
# Example:
288+
port: 80 # is passed as `config.port` to `salt://path-to-site-file/mysite2` template
289+
custom_key: custom_value
284290

285291
# Below configuration becomes handy if you want to create custom
286292
# configuration files for example if you want to create

0 commit comments

Comments
 (0)