Skip to content

Commit 589d668

Browse files
alessfggdzien
authored andcommitted
Add parameter to cleanup existing NGINX configs (#103)
1 parent 171b7d0 commit 589d668

File tree

6 files changed

+59
-36
lines changed

6 files changed

+59
-36
lines changed

README.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ nginx_install_from: nginx_repository
186186

187187
# Choose where to fetch the NGINX signing key from.
188188
# Default is the official NGINX signing key host.
189-
nginx_signing_key: https://nginx.org/keys/nginx_signing.key
189+
nginx_signing_key: http://nginx.org/keys/nginx_signing.key
190190

191191
# Specify source repository for NGINX Open Source.
192192
# Only works if 'install_from' is set to 'nginx_repository'.
@@ -248,36 +248,28 @@ nginx_controller_api_endpoint: null
248248
nginx_unit_enable: false
249249
nginx_unit_modules: null
250250

251-
# Enable NGINX status data.
252-
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
251+
# Remove previously existing NGINX configuration files.
252+
# Use a list of paths you wish to remove.
253253
# Default is false.
254-
nginx_status_enable: false
255-
nginx_status_port: 8080
256-
257-
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
258-
# Requires NGINX Plus.
259-
# Default is false.
260-
nginx_rest_api_enable: false
261-
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
262-
nginx_rest_api_port: 8080
263-
nginx_rest_api_write: false
264-
nginx_rest_api_dashboard: false
254+
nginx_cleanup_config: false
255+
nginx_cleanup_config_path:
256+
- /etc/nginx/conf.d
265257

266258
# Enable uploading NGINX configuration files to your system.
267259
# Default for uploading files is false.
268260
# Default location of files is the files folder within the NGINX Ansible role.
269261
# Upload the main NGINX configuration file.
270262
nginx_main_upload_enable: false
271263
nginx_main_upload_src: conf/nginx.conf
272-
nginx_main_upload_dest: /etc/nginx
264+
nginx_main_upload_dest: /etc/nginx/
273265
# Upload HTTP NGINX configuration files.
274266
nginx_http_upload_enable: false
275267
nginx_http_upload_src: conf/http/*.conf
276-
nginx_http_upload_dest: /etc/nginx/conf.d
268+
nginx_http_upload_dest: /etc/nginx/conf.d/
277269
# Upload Stream NGINX configuration files.
278270
nginx_stream_upload_enable: false
279271
nginx_stream_upload_src: conf/stream/*.conf
280-
nginx_stream_upload_dest: /etc/nginx/conf.d
272+
nginx_stream_upload_dest: /etc/nginx/conf.d/
281273
# Upload HTML files.
282274
nginx_html_upload_enable: false
283275
nginx_html_upload_src: www/*
@@ -321,8 +313,6 @@ nginx_main_template:
321313
# Enable creating dynamic templated NGINX HTTP configuration files.
322314
# Defaults will not produce a valid configuration. Instead they are meant to showcase
323315
# the options available for templating. Each key represents a new configuration file.
324-
# Comment out reverse_proxy or web_server depending on whether you wish to create a web server
325-
# or load balancer configuration file.
326316
nginx_http_template_enable: false
327317
nginx_http_template:
328318
default:
@@ -336,8 +326,8 @@ nginx_http_template:
336326
https_redirect: false
337327
autoindex: false
338328
ssl:
339-
cert: ssl/default.crt
340-
key: ssl/default.key
329+
cert: /etc/ssl/certs/default.crt
330+
key: /etc/ssl/private/default.key
341331
web_server:
342332
locations:
343333
default:
@@ -388,7 +378,6 @@ nginx_http_template:
388378
auth_basic: null
389379
auth_basic_file: null
390380
health_check_plus: false
391-
proxy_cache_enable: false
392381
proxy_cache:
393382
proxy_cache_path:
394383
path: /var/cache/nginx
@@ -401,7 +390,7 @@ nginx_http_template:
401390
upstream1:
402391
name: backend
403392
lb_method: least_conn
404-
zone_name: backend
393+
zone_name: backend_mem_zone
405394
zone_size: 64k
406395
sticky_cookie: false
407396
servers:
@@ -411,6 +400,21 @@ nginx_http_template:
411400
weight: 1
412401
health_check: max_fails=1 fail_timeout=10s
413402

403+
# Enable NGINX status data.
404+
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
405+
# Default is false.
406+
nginx_status_enable: false
407+
nginx_status_port: 8080
408+
409+
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
410+
# Requires NGINX Plus.
411+
# Default is false.
412+
nginx_rest_api_enable: false
413+
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
414+
nginx_rest_api_port: 8080
415+
nginx_rest_api_write: false
416+
nginx_rest_api_dashboard: false
417+
414418
# Enable creating dynamic templated NGINX stream configuration files.
415419
# Defaults will not produce a valid configuration. Instead they are meant to showcase
416420
# the options available for templating. Each key represents a new configuration file.

defaults/main.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,12 @@ nginx_controller_api_endpoint: null
8181
nginx_unit_enable: false
8282
nginx_unit_modules: null
8383

84-
# Enable NGINX status data.
85-
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
86-
# Default is false.
87-
nginx_status_enable: false
88-
nginx_status_port: 8080
89-
90-
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
91-
# Requires NGINX Plus.
84+
# Remove previously existing NGINX configuration files.
85+
# Use a list of paths you wish to remove.
9286
# Default is false.
93-
nginx_rest_api_enable: false
94-
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
95-
nginx_rest_api_port: 8080
96-
nginx_rest_api_write: false
97-
nginx_rest_api_dashboard: false
87+
nginx_cleanup_config: false
88+
nginx_cleanup_config_path:
89+
- /etc/nginx/conf.d
9890

9991
# Enable uploading NGINX configuration files to your system.
10092
# Default for uploading files is false.
@@ -241,6 +233,21 @@ nginx_http_template:
241233
weight: 1
242234
health_check: max_fails=1 fail_timeout=10s
243235

236+
# Enable NGINX status data.
237+
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
238+
# Default is false.
239+
nginx_status_enable: false
240+
nginx_status_port: 8080
241+
242+
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
243+
# Requires NGINX Plus.
244+
# Default is false.
245+
nginx_rest_api_enable: false
246+
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
247+
nginx_rest_api_port: 8080
248+
nginx_rest_api_write: false
249+
nginx_rest_api_dashboard: false
250+
244251
# Enable creating dynamic templated NGINX stream configuration files.
245252
# Defaults will not produce a valid configuration. Instead they are meant to showcase
246253
# the options available for templating. Each key represents a new configuration file.

tasks/conf/cleanup-config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: "(Setup: All OSs) Remove NGINX configuration files"
3+
file:
4+
path: "{{ item }}"
5+
state: absent
6+
with_items:
7+
- "{{ nginx_cleanup_config_path }}"

tasks/conf/template-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
template:
1111
src: "{{ item.value.template_file }}"
1212
dest: "{{ item.value.html_file_location }}/{{ item.value.html_file_name }}"
13+
backup: yes
1314
with_dict: "{{ nginx_html_demo_template }}"
1415
when: nginx_html_demo_template_enable
1516

tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
- import_tasks: plus/install-plus.yml
2828
when: nginx_type == "plus"
2929

30+
- import_tasks: conf/cleanup-config.yml
31+
when: nginx_cleanup_config
32+
3033
- import_tasks: modules/install-modules.yml
3134
when: true in nginx_modules.values()
3235

tests/playbooks/nginx-stream-template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
roles:
66
- ansible-role-nginx
77
vars:
8+
nginx_debug_output: true
89
nginx_main_template_enable: true
910
nginx_main_template:
1011
template_file: nginx.conf.j2

0 commit comments

Comments
 (0)