Skip to content

Commit a30001d

Browse files
Merge pull request #269 from netmanagers/master
Check nginx config before deploying & various passenger fixes
2 parents 63d32a4 + eedfc56 commit a30001d

File tree

16 files changed

+286
-12
lines changed

16 files changed

+286
-12
lines changed

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ignore: |
1414
.cache/
1515
.git/
1616
node_modules/
17-
test/**/states/**/*.sls
17+
test/salt/**/*.sls
1818
.kitchen/
1919
2020
yaml-files:

nginx/config.sls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ 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/map.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'Debian': {
1010
'package': 'nginx',
1111
'passenger_package': 'passenger',
12-
'passenger_config_file': '/etc/nginx/conf.d/passenger.conf',
12+
'passenger_config_file': '/etc/nginx/conf.d/mod-http-passenger.conf',
1313
'service': 'nginx',
1414
'webuser': 'www-data',
1515
'conf_file': '/etc/nginx/nginx.conf',
@@ -112,6 +112,7 @@
112112
'install_from_ppa': False,
113113
'install_from_repo': False,
114114
'install_from_phusionpassenger': False,
115+
'check_config_before_apply': False,
115116
'ppa_version': 'stable',
116117
'source_version': '1.10.0',
117118
'source_hash': '8ed647c3dd65bc4ced03b0e0f6bf9e633eff6b01bac772bcf97077d58bc2be4d',

nginx/passenger.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ passenger_install:
2525
- pkg: nginx_install
2626
- require_in:
2727
- service: nginx_service
28+
- file: nginx_config
2829
2930
/etc/nginx/passenger.conf:
3031
file.absent:
@@ -46,6 +47,7 @@ passenger_config:
4647
- service: nginx_service
4748
- require_in:
4849
- service: nginx_service
50+
- file: nginx_config
4951
- require:
5052
- file: /etc/nginx/passenger.conf
5153
- pkg: passenger_install

nginx/pkg.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ nginx_phusionpassenger_yum_repo:
163163
- baseurl: 'https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch'
164164
- repo_gpgcheck: 1
165165
- gpgcheck: 0
166-
- gpgkey: 'https://packagecloud.io/gpg.key'
166+
- gpgkey: 'https://oss-binaries.phusionpassenger.com/yum/definitions/RPM-GPG-KEY.asc'
167167
- enabled: True
168168
- sslverify: 1
169169
- sslcacert: /etc/pki/tls/certs/ca-bundle.crt

nginx/snippets.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ nginx_snippet_{{ snippet }}:
2828
- context:
2929
config: {{ config|json() }}
3030
nginx: {{ _nginx|json() }}
31+
- require:
32+
- file: nginx_snippets_dir
33+
- require_in:
34+
- file: nginx_config
35+
- service: nginx_service
3136
{% endfor %}

pillar.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ nginx:
2828
source_version: '1.10.0'
2929
source_hash: ''
3030

31+
# Check the configuration before applying:
32+
# To prevent applying a configuration that might break nginx, set this
33+
# parameter to true so the configuration is checked BEFORE applying. If
34+
# the check fails, the state will fail and it won't be deployed.
35+
# CAVEAT: As the configuration file is created in a temp dir, it can't
36+
# have relative references or it will fail to check. You'll need to
37+
# specify full paths where required (ie, `include`, `load_module`,
38+
# `snippets`, etc.0
39+
# Defaults to false
40+
check_config_before_apply: false
41+
3142
# These are usually set by grains in map.jinja
3243
# Typically you can comment these out.
3344
lookup:

test/integration/default/controls/config.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# frozen_string_literal: true
2+
13
# Set defaults, use debian as base
24

35
server_available = '/etc/nginx/sites-available'
4-
server_enabled = '/etc/nginx/sites-enabled'
6+
server_enabled = '/etc/nginx/sites-enabled'
57

68
# Override by platform family
79
case platform[:family]
8-
when 'redhat','fedora'
10+
when 'redhat', 'fedora'
911
server_available = '/etc/nginx/conf.d'
1012
server_enabled = '/etc/nginx/conf.d'
1113
when 'suse'
@@ -22,9 +24,13 @@
2224
it { should be_owned_by 'root' }
2325
it { should be_grouped_into 'root' }
2426
its('mode') { should cmp '0644' }
25-
its('content') { should include %Q[ log_format main '$remote_addr - $remote_user [$time_local] $status '
27+
its('content') do
28+
# rubocop:disable Metrics/LineLength
29+
should include %( log_format main '$remote_addr - $remote_user [$time_local] $status '
2630
'"$request" $body_bytes_sent "$http_referer" '
27-
'"$http_user_agent" "$http_x_forwarded_for"';] }
31+
'"$http_user_agent" "$http_x_forwarded_for"';)
32+
# rubocop:enable Metrics/LineLength
33+
end
2834
end
2935

3036
# snippets configuration
@@ -40,12 +46,11 @@
4046

4147
# sites configuration
4248
[server_available, server_enabled].each do |dir|
43-
44-
describe file ("#{dir}/default") do
45-
it { should_not exist }
49+
describe file "#{dir}/default" do
50+
it { should_not exist }
4651
end
4752

48-
describe file ("#{dir}/mysite") do
53+
describe file "#{dir}/mysite" do
4954
it { should be_file }
5055
it { should be_owned_by 'root' }
5156
it { should be_grouped_into 'root' }
@@ -57,6 +62,5 @@
5762
its('content') { should include 'try_files $uri $uri/ =404;' }
5863
its('content') { should include 'include snippets/letsencrypt.conf;' }
5964
end
60-
6165
end
6266
end

test/integration/default/controls/install.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'Nginx package' do
24
title 'should be installed'
35

test/integration/default/controls/service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'Nginx service' do
24
title 'should be running and enabled'
35

0 commit comments

Comments
 (0)