Skip to content

Commit 0fc5070

Browse files
daksmyii
authored andcommitted
refactor: replace old nginx with nginx.ng
BREAKING CHANGE: all previous `nginx` based configurations must be reviewed; `nginx.ng` usage must be promoted to `nginx` and any uses of the original `nginx` will have to be converted.
1 parent 90d2601 commit 0fc5070

35 files changed

+586
-1780
lines changed

docs/README.rst

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,99 +17,50 @@ Available states
1717
:local:
1818

1919
``nginx``
20-
---------
21-
22-
Runs the states to install nginx, configure the common files, and the users.
23-
24-
``nginx.common``
25-
----------------
26-
27-
Ensures standard nginx files are in place, and configures enabled sites.
28-
29-
``nginx.luajit2``
30-
-----------------
31-
32-
Installs luajit.
33-
34-
``nginx.openresty``
35-
-------------------
36-
37-
Installs openresty.
38-
39-
``nginx.package``
40-
-----------------
41-
42-
Installs the nginx package via package manager.
43-
44-
``nginx.source``
45-
----------------
46-
47-
Installs nginx via the source files.
48-
49-
``nginx.users``
50-
---------------
51-
52-
Installs apache utils, and configures nginx users specified in the pillar.
53-
This requires `basicauth <https://github.com/saltstack/salt-contrib/blob/master/modules/basicauth.py>`_
54-
from `salt-contrib <https://github.com/saltstack/salt-contrib/>`_ (either add it to your salt or ship
55-
this single file in your `_modules` directory see `Dynamic Module Distribution
56-
<https://docs.saltstack.com/en/latest/ref/file_server/dynamic-modules.html>`_
57-
58-
Next-generation, alternate approach
59-
===================================
60-
61-
The following states provide an alternate approach to managing Nginx and Nginx
62-
servers, as well as code organization. Please provide feedback by filing issues,
63-
discussing in ``#salt`` in Freenode and the mailing list as normal.
64-
65-
.. contents::
66-
:local:
67-
68-
``nginx.ng``
6920
------------
7021

71-
Meta-state for inclusion of all ng states.
22+
Meta-state for inclusion of all states.
7223

73-
**Note:** nginx.ng requires the merge parameter of salt.modules.pillar.get(),
24+
**Note:** nginx requires the merge parameter of salt.modules.pillar.get(),
7425
first available in the Helium release.
7526

76-
``nginx.ng.pkg``
27+
``nginx.pkg``
7728
--------------------
7829

7930
Installs nginx from package, from the distribution repositories, the official nginx repo or the ppa from Launchpad.
8031

81-
``nginx.ng.src``
32+
``nginx.src``
8233
--------------------
8334

8435
Builds and installs nginx from source.
8536

86-
``nginx.ng.certificates``
37+
``nginx.certificates``
8738
-------------------
8839

8940
Manages the deployment of nginx certificates.
9041

91-
``nginx.ng.config``
42+
``nginx.config``
9243
-------------------
9344

9445
Manages the nginx main server configuration file.
9546

96-
``nginx.ng.service``
47+
``nginx.service``
9748
--------------------
9849

9950
Manages the startup and running state of the nginx service.
10051

101-
``nginx.ng.servers_config``
52+
``nginx.servers_config``
10253
--------------------------
10354

10455
Manages virtual host files. This state only manages the content of the files
10556
and does not bind them to service calls.
10657

107-
``nginx.ng.servers``
58+
``nginx.servers``
10859
-------------------
10960

11061
Manages nginx virtual hosts files and binds them to service calls.
11162

112-
``nginx.ng.passenger``
63+
``nginx.passenger``
11364
----------------------
11465

11566
Installs and configures Phusion Passenger module for nginx. You need to enable

docs/TOFS_pattern.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Using SaltStack is a simple and effective way to implement configuration managem
3939

4040
To avoid this situation we can use the `pillar mechanism <http://docs.saltstack.com/en/latest/topics/pillar/>`_, which is designed to provide controlled access to data from the minions based on some selection rules. As pillar data could be easily integrated in the `Jinja <http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html>`_ templates, it is a good mechanism to store values to be used in the final rendering of state files and templates.
4141

42-
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/ng/files/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
42+
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/files/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
4343

4444
In opposition to the *put the code in file_roots and the data in pillars* approach, there is the *pillar as a store for a set of key-values* approach. A full-blown configuration file abstracted in pillar and jinja is complicated to develop, understand and maintain. I think a better and simpler approach is to keep a configuration file templated using just a basic (non-extensive but extensible) set of pillar values.
4545

kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ provisioner:
7272
state_top:
7373
base:
7474
'*':
75-
- nginx.ng
75+
- nginx
7676
pillars:
7777
top.sls:
7878
base:

nginx/ng/certificates.sls renamed to nginx/certificates.sls

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
{% from 'nginx/ng/map.jinja' import nginx with context %}
1+
{% from 'nginx/map.jinja' import nginx with context %}
22
33
include:
4-
- nginx.ng.service
4+
- nginx.service
55
6-
{% set certificates_path = salt['pillar.get']('nginx:ng:certificates_path', '/etc/nginx/ssl') %}
6+
{% set certificates_path = salt['pillar.get']('nginx:certificates_path', '/etc/nginx/ssl') %}
77
8-
{%- for dh_param, value in salt['pillar.get']('nginx:ng:dh_param', {}).items() %}
8+
{%- for dh_param, value in salt['pillar.get']('nginx:dh_param', {}).items() %}
99
{%- if value is string %}
1010
create_nginx_dhparam_{{ dh_param }}_key:
1111
file.managed:
1212
- name: {{ certificates_path }}/{{ dh_param }}
13-
- contents_pillar: nginx:ng:dh_param:{{ dh_param }}
13+
- contents_pillar: nginx:dh_param:{{ dh_param }}
1414
- makedirs: True
1515
- watch_in:
1616
- service: nginx_service
@@ -30,30 +30,30 @@ generate_nginx_dhparam_{{ dh_param }}_key:
3030
{%- endif %}
3131
{%- endfor %}
3232
33-
{%- for domain in salt['pillar.get']('nginx:ng:certificates', {}).keys() %}
33+
{%- for domain in salt['pillar.get']('nginx:certificates', {}).keys() %}
3434
3535
nginx_{{ domain }}_ssl_certificate:
3636
file.managed:
3737
- name: {{ certificates_path }}/{{ domain }}.crt
3838
- makedirs: True
39-
{% if salt['pillar.get']("nginx:ng:certificates:{}:public_cert_pillar".format(domain)) %}
40-
- contents_pillar: {{salt['pillar.get']('nginx:ng:certificates:{}:public_cert_pillar'.format(domain))}}
39+
{% if salt['pillar.get']("nginx:certificates:{}:public_cert_pillar".format(domain)) %}
40+
- contents_pillar: {{salt['pillar.get']('nginx:certificates:{}:public_cert_pillar'.format(domain))}}
4141
{% else %}
42-
- contents_pillar: nginx:ng:certificates:{{ domain }}:public_cert
42+
- contents_pillar: nginx:certificates:{{ domain }}:public_cert
4343
{% endif %}
4444
- watch_in:
4545
- service: nginx_service
4646
47-
{% if salt['pillar.get']("nginx:ng:certificates:{}:private_key".format(domain)) or salt['pillar.get']("nginx:ng:certificates:{}:private_key_pillar".format(domain))%}
47+
{% if salt['pillar.get']("nginx:certificates:{}:private_key".format(domain)) or salt['pillar.get']("nginx:certificates:{}:private_key_pillar".format(domain))%}
4848
nginx_{{ domain }}_ssl_key:
4949
file.managed:
5050
- name: {{ certificates_path }}/{{ domain }}.key
5151
- mode: 600
5252
- makedirs: True
53-
{% if salt['pillar.get']("nginx:ng:certificates:{}:private_key_pillar".format(domain)) %}
54-
- contents_pillar: {{salt['pillar.get']('nginx:ng:certificates:{}:private_key_pillar'.format(domain))}}
53+
{% if salt['pillar.get']("nginx:certificates:{}:private_key_pillar".format(domain)) %}
54+
- contents_pillar: {{salt['pillar.get']('nginx:certificates:{}:private_key_pillar'.format(domain))}}
5555
{% else %}
56-
- contents_pillar: nginx:ng:certificates:{{ domain }}:private_key
56+
- contents_pillar: nginx:certificates:{{ domain }}:private_key
5757
{% endif %}
5858
- watch_in:
5959
- service: nginx_service

nginx/common.sls

Lines changed: 0 additions & 58 deletions
This file was deleted.

nginx/ng/config.sls renamed to nginx/config.sls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# nginx.ng.config
1+
# nginx.config
22
#
33
# Manages the main nginx server configuration file.
44

5-
{% from 'nginx/ng/map.jinja' import nginx, sls_block with context %}
5+
{% from 'nginx/map.jinja' import nginx, sls_block with context %}
66
77
{% if nginx.install_from_source %}
88
nginx_log_dir:
@@ -15,7 +15,7 @@ nginx_log_dir:
1515
{% if 'source_path' in nginx.server.config %}
1616
{% set source_path = nginx.server.config.source_path %}
1717
{% else %}
18-
{% set source_path = 'salt://nginx/ng/files/nginx.conf' %}
18+
{% set source_path = 'salt://nginx/files/nginx.conf' %}
1919
{% endif %}
2020
nginx_config:
2121
file.managed:
File renamed without changes.
File renamed without changes.
File renamed without changes.

nginx/init.sls

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
{% from "nginx/map.jinja" import nginx as nginx_map with context %}
1+
# nginx
2+
#
3+
# Meta-state to fully install nginx.
4+
5+
{% from 'nginx/map.jinja' import nginx, sls_block with context %}
26
37
include:
4-
- nginx.common
5-
{% if salt['pillar.get']('nginx:use_upstart', nginx_map['use_upstart']) %}
6-
- nginx.upstart
7-
{% elif salt['pillar.get']('nginx:use_sysvinit', nginx_map['use_sysvinit']) %}
8-
- nginx.sysvinit
9-
{% endif %}
10-
{% if pillar.get('nginx', {}).get('user_auth_enabled', true) %}
11-
- nginx.users
12-
{% endif %}
13-
{% if pillar.get('nginx', {}).get('install_from_source', false) %}
14-
- nginx.source
15-
{% else %}
16-
- nginx.package
17-
{% endif -%}
8+
- nginx.config
9+
- nginx.service
10+
{% if nginx.snippets is defined %}
11+
- nginx.snippets
12+
{% endif %}
13+
- nginx.servers
14+
- nginx.certificates
1815
16+
extend:
17+
nginx_service:
18+
service:
19+
- listen:
20+
- file: nginx_config
21+
- require:
22+
- file: nginx_config
23+
nginx_config:
24+
file:
25+
- require:
26+
{% if nginx.install_from_source %}
27+
- cmd: nginx_install
28+
{% else %}
29+
- pkg: nginx_install
30+
{% endif %}

0 commit comments

Comments
 (0)