Merge pull request #278 from netmanagers/master
feat(servers_config): add require statement to manage dependencies
This commit is contained in:
commit
6ec5bf2916
@ -373,9 +373,13 @@ verifier:
|
|||||||
suites:
|
suites:
|
||||||
- name: default
|
- name: default
|
||||||
provisioner:
|
provisioner:
|
||||||
|
dependencies:
|
||||||
|
- name: test_dep
|
||||||
|
path: test/salt/default/states
|
||||||
state_top:
|
state_top:
|
||||||
base:
|
base:
|
||||||
'*':
|
'*':
|
||||||
|
- test_dep.create_dependency_file
|
||||||
- nginx._mapdata
|
- nginx._mapdata
|
||||||
- nginx
|
- nginx
|
||||||
pillars:
|
pillars:
|
||||||
|
@ -31,6 +31,3 @@ nginx_config:
|
|||||||
- context:
|
- context:
|
||||||
config: {{ nginx.server.config|json(sort_keys=False) }}
|
config: {{ nginx.server.config|json(sort_keys=False) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if nginx.check_config_before_apply %}
|
|
||||||
- check_cmd: /usr/sbin/nginx -t -c
|
|
||||||
{% endif %}
|
|
||||||
|
@ -123,6 +123,12 @@ nginx_server_available_dir:
|
|||||||
}}
|
}}
|
||||||
- makedirs: True
|
- makedirs: True
|
||||||
- template: jinja
|
- template: jinja
|
||||||
|
{%- if 'requires' in settings %}
|
||||||
|
- require:
|
||||||
|
{%- for k, v in settings.requires.items() %}
|
||||||
|
- {{ k }}: {{ v }}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- endif %}
|
||||||
{% if 'source_path' not in settings.config %}
|
{% if 'source_path' not in settings.config %}
|
||||||
- context:
|
- context:
|
||||||
config: {{ settings.config|json(sort_keys=False) }}
|
config: {{ settings.config|json(sort_keys=False) }}
|
||||||
|
@ -42,3 +42,6 @@ nginx_service:
|
|||||||
{% else %}
|
{% else %}
|
||||||
- pkg: nginx_install
|
- pkg: nginx_install
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if nginx.check_config_before_apply %}
|
||||||
|
- only_if: /usr/sbin/nginx -t
|
||||||
|
{% endif %}
|
||||||
|
@ -202,6 +202,18 @@ nginx:
|
|||||||
# and None indicates no action
|
# and None indicates no action
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
# This let's you add dependencies on other resources being applied for a
|
||||||
|
# particular vhost
|
||||||
|
# A common case is when you use this formula together with letsencrypt's,
|
||||||
|
# validating through nginx: you need nginx running (to validate the vhost) but
|
||||||
|
# can't have the ssl vhost up until the certificate is created (because it
|
||||||
|
# won't exist and will make nginx fail to load the configuration)
|
||||||
|
#
|
||||||
|
# An example, when using LE to create the cert for 'some.host.domain':
|
||||||
|
# requires:
|
||||||
|
# cmd: create-initial-cert-some.host.domain
|
||||||
|
requires: {}
|
||||||
|
|
||||||
# Remove the site config file shipped by nginx
|
# Remove the site config file shipped by nginx
|
||||||
# (i.e. '/etc/nginx/sites-available/default' by default)
|
# (i.e. '/etc/nginx/sites-available/default' by default)
|
||||||
# It also remove the symlink (if it is exists).
|
# It also remove the symlink (if it is exists).
|
||||||
|
@ -71,5 +71,16 @@ control 'Nginx configuration' do
|
|||||||
its('content') { should include 'try_files $uri $uri/ =404;' }
|
its('content') { should include 'try_files $uri $uri/ =404;' }
|
||||||
its('content') { should include 'include snippets/letsencrypt.conf;' }
|
its('content') { should include 'include snippets/letsencrypt.conf;' }
|
||||||
end
|
end
|
||||||
|
describe file "#{dir}/mysite_with_require" do
|
||||||
|
it { should be_file }
|
||||||
|
it { should be_owned_by file_owner }
|
||||||
|
it { should be_grouped_into file_group }
|
||||||
|
its('mode') { should cmp '0644' }
|
||||||
|
its('content') { should include 'server_name with-deps;' }
|
||||||
|
its('content') { should include 'listen 80;' }
|
||||||
|
its('content') { should include 'index index.html index.htm;' }
|
||||||
|
its('content') { should include 'location ~ .htm {' }
|
||||||
|
its('content') { should include 'try_files $uri $uri/ =404;' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
9
test/integration/default/controls/file.rb
Normal file
9
test/integration/default/controls/file.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
control 'Dependency test file' do
|
||||||
|
title 'should exist'
|
||||||
|
|
||||||
|
describe file('/tmp/created_to_test_dependencies') do
|
||||||
|
it { should be_file }
|
||||||
|
end
|
||||||
|
end
|
@ -37,6 +37,19 @@ nginx:
|
|||||||
- location ~ .htm:
|
- location ~ .htm:
|
||||||
- try_files: '$uri $uri/ =404'
|
- try_files: '$uri $uri/ =404'
|
||||||
- include: 'snippets/letsencrypt.conf'
|
- include: 'snippets/letsencrypt.conf'
|
||||||
|
mysite_with_require:
|
||||||
|
enabled: true
|
||||||
|
config:
|
||||||
|
- server:
|
||||||
|
- server_name: with-deps
|
||||||
|
- listen:
|
||||||
|
- '80'
|
||||||
|
- index: 'index.html index.htm'
|
||||||
|
- location ~ .htm:
|
||||||
|
- try_files: '$uri $uri/ =404'
|
||||||
|
requires:
|
||||||
|
file: created_to_test_dependencies
|
||||||
|
|
||||||
dh_param:
|
dh_param:
|
||||||
'mydhparam2.pem':
|
'mydhparam2.pem':
|
||||||
keysize: 2048
|
keysize: 2048
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
## this state creates a file that is used to test vhosts dependencies
|
||||||
|
# (see https://github.com/saltstack-formulas/nginx-formula/pull/278)
|
||||||
|
|
||||||
|
created_to_test_dependencies:
|
||||||
|
file.managed:
|
||||||
|
- name: /tmp/created_to_test_dependencies
|
@ -26,7 +26,6 @@ nginx:
|
|||||||
- location ^~ /.well-known/acme-challenge/:
|
- location ^~ /.well-known/acme-challenge/:
|
||||||
- proxy_pass: http://localhost:9999
|
- proxy_pass: http://localhost:9999
|
||||||
server:
|
server:
|
||||||
|
|
||||||
config:
|
config:
|
||||||
# This is required to get the passenger module loaded
|
# This is required to get the passenger module loaded
|
||||||
# In Debian it can be done with this
|
# In Debian it can be done with this
|
||||||
@ -64,5 +63,4 @@ nginx:
|
|||||||
- index: 'index.html index.htm'
|
- index: 'index.html index.htm'
|
||||||
- location ~ .htm:
|
- location ~ .htm:
|
||||||
- try_files: '$uri $uri/ =404'
|
- try_files: '$uri $uri/ =404'
|
||||||
# - include: '/etc/nginx/snippets/letsencrypt.conf'
|
- include: '/etc/nginx/snippets/letsencrypt.conf'
|
||||||
- include: 'snippets/letsencrypt.conf'
|
|
||||||
|
Loading…
Reference in New Issue
Block a user