Skip to content

Commit c1fcab2

Browse files
authored
Refactor modules (#22)
1 parent 1e46135 commit c1fcab2

File tree

10 files changed

+46
-51
lines changed

10 files changed

+46
-51
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22

3-
## 0.1.1 (Unreleased)
3+
## 0.2.0 (Unreleased)
4+
5+
BREAKING CHANGES:
6+
7+
* The process to configure modules has changed. Instead of manually setting the modules you want to install to `true` or `false`, you will now have to use either:
8+
* A newly introduced top level list variable, `nginx_config_modules`.
9+
* A newly introduced list variable within your main NGINX config template, `nginx_config_main_template.modules`.
10+
11+
Make sure you only use one variable or the other, since they will overwrite each other. This change will simplify adding future supported modules to this role, and allows you to include any external modules you may wish in your NGINX config.
412

513
ENHANCEMENTS:
614

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Example Playbooks
135135
Working functional playbook examples can be found in the **`molecule/common`** directory in the following files:
136136

137137
- **[molecule/common/playbooks/default_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/master/molecule/common/playbooks/default_converge.yml):** Use the NGINX configuration templating variables to create an NGINX configuration file
138-
- **[molecule/common/playbooks/module_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/master/molecule/common/playbooks/module_converge.yml):** Install and configure NGINX supported modules
138+
- **[molecule/common/playbooks/module_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/master/molecule/common/playbooks/module_converge.yml):** Cleanup NGINX configs and configure NGINX supported modules
139139
- **[molecule/common/playbooks/stable_push_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/master/molecule/common/playbooks/stable_push_converge.yml):** Install NGINX using the stable branch and push a preexisting config from your system to your NGINX instance
140140

141141
Do note that if you install this repository via Ansible Galaxy, you will have to replace the role variable in the sample playbooks from `ansible-role-nginx-config` to `nginxinc.nginx_config`.

defaults/main/main.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ nginx_config_start: true
66
# Print NGINX configuration file to terminal after executing playbook.
77
nginx_config_debug_output: false
88

9-
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming (NGINX Plus only), and/or XSLT modules.
10-
# Default is false.
11-
nginx_config_modules:
12-
njs: false
13-
perl: false
14-
waf: false
15-
geoip: false
16-
image_filter: false
17-
rtmp: false
18-
xslt: false
19-
209
# Remove previously existing NGINX configuration files (files ending in *.conf).
2110
# You can specify a list of paths you wish to remove.
2211
# You can also choose whether to recurse through the paths specified.
@@ -29,3 +18,8 @@ nginx_config_cleanup: false
2918
# recurse: false
3019
# nginx_config_cleanup_files:
3120
# - /etc/nginx/conf.d/default.conf
21+
22+
# Add select modules to the beginning of your `nginx.conf` file. Do not use if
23+
# you are already setting modules via 'nginx_config_main_template'.
24+
# nginx_config_modules:
25+
# - modules/ngx_http_js_module.so

defaults/main/template.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ nginx_config_main_template:
1515
template_file: nginx.conf.j2
1616
conf_file_name: nginx.conf
1717
conf_file_location: /etc/nginx/
18+
# modules: # specify modules as a list following the format in the line below
19+
# - modules/ngx_http_js_module.so
1820
user: nginx
1921
worker_processes: auto
2022
# worker_rlimit_nofile: 1024

molecule/common/playbooks/default_converge.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
template_file: nginx.conf.j2
1515
conf_file_name: nginx.conf
1616
conf_file_location: /etc/nginx/
17+
modules:
18+
- modules/ngx_http_js_module.so
1719
user: nginx
1820
worker_processes: auto
1921
pid: /var/run/nginx.pid

molecule/common/playbooks/module_converge.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,4 @@
1717
- /etc/nginx/conf.d/default.conf
1818

1919
nginx_config_modules:
20-
njs: true
21-
perl: true
22-
waf: false
23-
geoip: true
24-
image_filter: true
25-
rtmp: true
26-
xslt: true
20+
- modules/ngx_http_js_module.so

molecule/common/playbooks/prepare.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
- name: Install NGINX
66
include_role:
77
name: nginxinc.nginx
8+
vars:
9+
nginx_modules:
10+
njs: true
11+
perl: false
12+
waf: false
13+
geoip: false
14+
image_filter: false
15+
rtmp: false
16+
xslt: false

tasks/conf/template-config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
with_dict: "{{ nginx_config_html_demo_template }}"
1717
when: nginx_config_html_demo_template_enable | bool
1818

19+
- name: "(Setup: All NGINX) Configure NGINX Modules"
20+
lineinfile:
21+
path: /etc/nginx/nginx.conf
22+
insertbefore: BOF
23+
line: "load_module {{ item }};"
24+
loop: "{{ nginx_config_modules }}"
25+
when:
26+
- nginx_config_modules is defined
27+
- nginx_config_modules | length > 0
28+
notify: "(Handler: All OSs) Start NGINX"
29+
1930
- name: "(Setup: All NGINX) Ensure NGINX Main Directory Exists"
2031
file:
2132
path: "{{ nginx_config_main_template.conf_file_location | default('/etc/nginx') }}"

tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
or nginx_config_http_template_enable | bool
2828
or nginx_config_stream_template_enable | bool
2929
or nginx_config_rest_api_enable | bool
30+
or nginx_config_html_demo_template_enable | bool
31+
or nginx_config_modules is defined and nginx_config_modules | length > 0
3032
tags: nginx_config_template
3133

3234
- name: "(Config: All OSs) Ensure NGINX is Running"

templates/nginx.conf.j2

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
11
{{ ansible_managed | comment }}
22

3-
{% if nginx_config_modules.njs %}
4-
{% if nginx_config_http_template_enable %}
5-
load_module modules/ngx_http_js_module.so;
6-
{% endif %}
7-
{% if nginx_config_stream_template_enable %}
8-
load_module modules/ngx_stream_js_module.so;
9-
{% endif %}
10-
{% endif %}
11-
{% if nginx_config_modules.perl %}
12-
load_module modules/ngx_http_perl_module.so;
13-
{% endif %}
14-
{% if nginx_config_modules.geoip %}
15-
{% if nginx_config_http_template_enable %}
16-
load_module modules/ngx_http_geoip_module.so;
17-
{% endif %}
18-
{% if nginx_config_stream_template_enable %}
19-
load_module modules/ngx_stream_geoip_module.so;
20-
{% endif %}
21-
{% endif %}
22-
{% if nginx_config_modules.image_filter %}
23-
load_module modules/ngx_http_image_filter_module.so;
24-
{% endif %}
25-
{% if nginx_config_modules.rtmp and nginx_type == "plus" %}
26-
load_module modules/ngx_rtmp_module.so;
27-
{% endif %}
28-
{% if nginx_config_modules.xslt %}
29-
load_module modules/ngx_http_xslt_filter_module.so;
30-
{% endif %}
31-
{% if nginx_config_modules.waf and nginx_type == "plus" %}
32-
load_module modules/ngx_http_modsecurity_module.so;
33-
{% endif %}
3+
{% for nginx_module in nginx_config_main_template.modules %}
4+
load_module {{ nginx_module }};
5+
{% endfor %}
6+
347
user {{ nginx_config_main_template.user }};
358
worker_processes {{ nginx_config_main_template.worker_processes }};
369

0 commit comments

Comments
 (0)