Skip to content

Commit 622d22f

Browse files
committed
feat(servers_config): add require statement to manage dependencies
Also, check config before applying
1 parent b9e9cd3 commit 622d22f

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

nginx/config.sls

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ nginx_config:
3131
- context:
3232
config: {{ nginx.server.config|json(sort_keys=False) }}
3333
{% endif %}
34-
{% if nginx.check_config_before_apply %}
35-
- check_cmd: /usr/sbin/nginx -t -c
36-
{% endif %}

nginx/servers_config.sls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ nginx_server_available_dir:
123123
}}
124124
- makedirs: True
125125
- template: jinja
126+
{%- if 'requires' in settings %}
127+
- require:
128+
{%- for k, v in settings.requires.items() %}
129+
- {{ k }}: {{ v }}
130+
{%- endfor %}
131+
{%- endif %}
126132
{% if 'source_path' not in settings.config %}
127133
- context:
128134
config: {{ settings.config|json(sort_keys=False) }}

nginx/service.sls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ nginx_service:
4242
{% else %}
4343
- pkg: nginx_install
4444
{% endif %}
45+
{% if nginx.check_config_before_apply %}
46+
- only_if: /usr/sbin/nginx -t
47+
{% endif %}

pillar.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ nginx:
202202
# and None indicates no action
203203
enabled: true
204204

205+
# This let's you add dependencies on other resources being applied for a
206+
# particular vhost
207+
# A common case is when you use this formula together with letsencrypt's,
208+
# validating through nginx: you need nginx running (to validate the vhost) but
209+
# can't have the ssl vhost up until the certificate is created (because it
210+
# won't exist and will make nginx fail to load the configuration)
211+
#
212+
# An example, when using LE to create the cert for 'some.host.domain':
213+
# requires:
214+
# cmd: create-initial-cert-some.host.domain
215+
requires: {}
216+
205217
# Remove the site config file shipped by nginx
206218
# (i.e. '/etc/nginx/sites-available/default' by default)
207219
# It also remove the symlink (if it is exists).

test/salt/passenger/pillar/nginx.sls

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ nginx:
2626
- location ^~ /.well-known/acme-challenge/:
2727
- proxy_pass: http://localhost:9999
2828
server:
29-
3029
config:
3130
# This is required to get the passenger module loaded
3231
# In Debian it can be done with this
@@ -64,5 +63,4 @@ nginx:
6463
- index: 'index.html index.htm'
6564
- location ~ .htm:
6665
- try_files: '$uri $uri/ =404'
67-
# - include: '/etc/nginx/snippets/letsencrypt.conf'
68-
- include: 'snippets/letsencrypt.conf'
66+
- include: '/etc/nginx/snippets/letsencrypt.conf'

0 commit comments

Comments
 (0)