Skip to content

Commit

Permalink
Make backup parameter optional (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessfg committed Dec 14, 2021
1 parent 5105b27 commit 028f954
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ BREAKING CHANGES:

Remove parameters deprecated in release `0.4.0`. To recap, these are `nginx_config_main_upload_*`, `nginx_config_upload_html_*`, and `nginx_config_stream_upload_*`. Use `nginx_config_upload` instead.

FEATURES:

Add `backup` variable to template and upload parameters. Set to `false` if you don't want to keep backups of your previous NGINX config files.

## 0.4.2 (October 28, 2021)

BUG FIXES:
Expand Down
6 changes: 6 additions & 0 deletions defaults/main/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ nginx_config_html_demo_template:
html_file_name: index.html
html_file_location: /usr/share/nginx/html
web_server_name: Default
backup: true

# Enable creating dynamic templated NGINX configuration files.
# Defaults are the values found in a fresh NGINX installation.
Expand All @@ -14,6 +15,7 @@ nginx_config_main_template_enable: false
nginx_config_main_template:
template_file: nginx.conf.j2
deployment_location: /etc/nginx/nginx.conf
backup: true
config:
main: # Configure NGINX main core directives
load_module: modules/ngx_http_js_module.so # String or a list of strings
Expand Down Expand Up @@ -78,6 +80,7 @@ nginx_config_http_template_enable: false
nginx_config_http_template:
- template_file: http/default.conf.j2
deployment_location: /etc/nginx/conf.d/default.conf
backup: true
config:
upstreams: # Configure NGINX upstreams
- name: backend # Required
Expand Down Expand Up @@ -672,6 +675,7 @@ nginx_config_http_template:
nginx_config_status_enable: false
nginx_config_status_template_file: http/status.conf.j2
nginx_config_status_file_location: /etc/nginx/conf.d/status.conf
nginx_config_status_backup: true
nginx_config_status_port: 8080 # Optional -- Defaults to 8080
nginx_config_status_access_log: # Optional -- Set to 'false' and remove/comment nested variables to disable access log
location: /var/log/nginx/access.log # Required
Expand All @@ -687,6 +691,7 @@ nginx_config_status_deny: # Optional
nginx_config_rest_api_enable: false
nginx_config_rest_api_template_file: http/api.conf.j2
nginx_config_rest_api_file_location: /etc/nginx/conf.d/api.conf
nginx_config_rest_api_backup: true
nginx_config_rest_api_port: 8080 # Optional-- Defaults to 8080
nginx_config_rest_api_write: false # Optional
nginx_config_rest_api_access_log: # Optional -- Set to 'false' and remove/comment nested variables to disable access log
Expand All @@ -710,6 +715,7 @@ nginx_config_stream_template:
- template_file: stream/default.conf.j2
conf_file_name: default.conf
conf_file_location: /etc/nginx/conf.d/stream/
backup: true
network_streams:
- listen:
- ip: 0.0.0.0 # Wrap in square brackets for IPv6 addresses
Expand Down
4 changes: 4 additions & 0 deletions defaults/main/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ nginx_config_upload_enable: false
nginx_config_upload:
- src: config/snippets/ # You can optionally also include the specific file name
dest: /etc/nginx/snippets # You can optionally also include the specific desired file name
backup: true
# Upload HTML files.
nginx_config_upload_html_enable: false
nginx_config_upload_html:
- src: www/index.html
dest: /usr/share/nginx/html
backup: true
# Upload SSL certificates and keys.
nginx_config_upload_ssl_enable: false
nginx_config_upload_ssl_crt:
- src: ssl/certs/
dest: /etc/ssl/certs
backup: true
nginx_config_upload_ssl_key:
- src: ssl/private/
dest: /etc/ssl/private
backup: true
10 changes: 9 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
nginx_config_upload_ssl_crt:
- src: ../common/files/ssl/molecule.crt
dest: /etc/ssl/certs
backup: true
nginx_config_upload_ssl_key:
- src: ../common/files/ssl/molecule.key
dest: /etc/ssl/private
backup: true

nginx_config_main_template_enable: true
nginx_config_main_template:
template_file: nginx.conf.j2
deployment_location: /etc/nginx/nginx.conf
backup: true
config:
main:
load_module:
Expand Down Expand Up @@ -75,14 +78,16 @@
- /etc/nginx/conf.d/stream/*.conf

nginx_config_status_enable: true
nginx_config_status_backup: true
nginx_config_status_port: 8080
nginx_config_status_access_log:
path: /var/log/nginx/access.log
format: main

nginx_config_http_template_enable: true
nginx_config_http_template:
- config:
- backup: true
config:
upstreams:
- name: frontend_servers
zone:
Expand Down Expand Up @@ -661,17 +666,20 @@
- template_file: www/index.html.j2
html_file_name: frontend_index.html
html_file_location: /usr/share/nginx/html
backup: true
web_server_name: Frontend
- template_file: www/index.html.j2
html_file_name: backend_index.html
html_file_location: /usr/share/nginx/html
backup: true
web_server_name: Backend

nginx_config_stream_template_enable: true
nginx_config_stream_template:
- template_file: stream/default.conf.j2
conf_file_name: stream_default.conf
conf_file_location: /etc/nginx/conf.d/stream
backup: true
network_streams:
- listen:
- ip: 0.0.0.0
Expand Down
1 change: 1 addition & 0 deletions molecule/plus/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- /etc/nginx/conf.d/stream/*.conf

nginx_config_rest_api_enable: true
nginx_config_rest_api_backup: true
nginx_config_rest_api_write: true
nginx_config_rest_api_access_log:
path: /var/log/nginx/access.log
Expand Down
5 changes: 5 additions & 0 deletions molecule/stable_push/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
nginx_config_upload:
- src: ../common/files/snippets/location_snippet.conf
dest: /etc/nginx/snippets
backup: true
- src: ../common/files/http/
dest: /etc/nginx/conf.d
backup: true
nginx_config_upload_html_enable: true
nginx_config_upload_html:
- src: ../common/files/www/index.html
dest: /usr/share/nginx/html
backup: true
nginx_config_upload_ssl_enable: true
nginx_config_upload_ssl_crt:
- src: ../common/files/ssl/molecule.crt
dest: /etc/ssl/certs
backup: true
nginx_config_upload_ssl_key:
- src: ../common/files/ssl/molecule.key
dest: /etc/ssl/private
backup: true
12 changes: 6 additions & 6 deletions tasks/config/template-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
template:
src: "{{ item.template_file | default('www/index.html.j2') }}"
dest: "{{ item.html_file_location | default('/usr/share/nginx/html') }}/{{ item.html_file_name | default('index.html') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0644
loop: "{{ nginx_config_html_demo_template }}"
when: nginx_config_html_demo_template_enable | bool
Expand All @@ -38,7 +38,7 @@
template:
src: "{{ nginx_config_main_template.template_file | default('nginx.conf.j2') }}"
dest: "{{ nginx_config_main_template.deployment_location | default('/etc/nginx/nginx.conf') }}"
backup: true
backup: "{{ nginx_config_main_template.backup | default(true) }}"
mode: 0644
when: nginx_config_main_template_enable | bool
notify: (Handler - NGINX Config) Run NGINX
Expand Down Expand Up @@ -67,7 +67,7 @@
template:
src: "{{ item.template_file | default('http/default.conf.j2') }}"
dest: "{{ item.deployment_location | default('/etc/nginx/conf.d/default.conf') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0644
loop: "{{ nginx_config_http_template }}"
when: nginx_config_http_template_enable | bool
Expand All @@ -77,7 +77,7 @@
template:
src: "{{ nginx_config_status_template_file | default('http/status.conf.j2') }}"
dest: "{{ nginx_config_status_file_location | default('/etc/nginx/conf.d/status.conf') }}"
backup: true
backup: "{{ nginx_config_status_backup | default(true) }}"
mode: 0644
notify: (Handler - NGINX Config) Run NGINX
when: nginx_config_status_enable | bool
Expand All @@ -86,7 +86,7 @@
template:
src: "{{ nginx_config_rest_api_template_file | default('http/api.conf.j2') }}"
dest: "{{ nginx_config_rest_api_file_location | default('/etc/nginx/conf.d/api.conf') }}"
backup: true
backup: "{{ nginx_config_rest_api_backup | default(true) }}"
mode: 0644
notify: (Handler - NGINX Config) Run NGINX
when: nginx_config_rest_api_enable | bool
Expand All @@ -103,7 +103,7 @@
template:
src: "{{ item.template_file | default('stream/default.conf.j2') }}"
dest: "{{ item.conf_file_location | default('/etc/nginx/conf.d/stream') }}/{{ item.conf_file_name | default('default.conf') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0644
loop: "{{ nginx_config_stream_template }}"
notify: (Handler - NGINX Config) Run NGINX
Expand Down
8 changes: 4 additions & 4 deletions tasks/config/upload-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
copy:
src: "{{ item.src }}"
dest: "{{ item.dest | default('/etc/nginx/') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0644
loop: "{{ nginx_config_upload }}"
notify: (Handler - NGINX Config) Run NGINX
Expand All @@ -31,7 +31,7 @@
copy:
src: "{{ item.src }}"
dest: "{{ item.dest | default('/usr/share/nginx/html') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0644
loop: "{{ nginx_config_upload_html }}"
notify: (Handler - NGINX Config) Run NGINX
Expand All @@ -50,15 +50,15 @@
copy:
src: "{{ item.src }}"
dest: "{{ item.dest | default('/etc/ssl/certs') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0640
loop: "{{ nginx_config_upload_ssl_crt }}"

- name: Upload NGINX SSL keys
copy:
src: "{{ item.src }}"
dest: "{{ item.dest | default('/etc/ssl/private') }}"
backup: true
backup: "{{ item.backup | default(true) }}"
mode: 0640
loop: "{{ nginx_config_upload_ssl_key }}"
no_log: true
Expand Down

0 comments on commit 028f954

Please sign in to comment.