Skip to content

Commit 5f1fc18

Browse files
authored
Improve uninstalling NGINX capabilities (#472)
1 parent c24e9d5 commit 5f1fc18

35 files changed

+563
-119
lines changed

.github/workflows/molecule.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- module
2424
- plus
2525
- source
26+
- uninstall
27+
- uninstall_plus
28+
- upgrade
2629
steps:
2730
- name: Check out the codebase
2831
if: "!(contains(matrix.scenario, 'plus') && github.event.pull_request.head.repo.full_name != github.repository)"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Thumbs.db
1919
# Python specific #
2020
###################
2121
__pycache__
22+
23+
# Logs #
24+
########
25+
*.log

CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

3-
## 0.21.4 (Unreleased)
3+
## 0.22.0 (Unreleased)
4+
5+
BREAKING CHANGES:
6+
7+
* The `nginx_state` variable has been replaced with `nginx_setup` and instead of using `present`, `absent`, `latest` you should now use `install`, `uninstall` and `upgrade`.
8+
* `nginx_install` variable is no more. Use `nginx_enable` instead.
49

510
FEATURES:
611

@@ -12,7 +17,8 @@ Add Alpine Linux 3.15 to list of tested and supported platforms.
1217

1318
BUG FIXES:
1419

15-
When building NGINX from source, the original source FTP repository `ftp.pcre.org` is not available anymore, according to <http://pcre.org>. The FTP repository has been updated to use `ftp.exim.org` instead.
20+
* When building NGINX from source, the original source FTP repository `ftp.pcre.org` is not available anymore, according to <http://pcre.org>. The FTP repository has been updated to use `ftp.exim.org` instead.
21+
* Uninstalling NGINX should now work correctly under most scenarios.
1622

1723
## 0.21.3 (October 25, 2021)
1824

@@ -217,7 +223,7 @@ FEATURES:
217223
* A new variable has been introduced:
218224
* `nginx_setup_license` -- Determine whether you want to use this role to upload your NGINX license to your target host.
219225
* The role will now fail automatically if you try to deploy NGINX from an official repository in an unsupported distribution. You can find a list of supported distributions for NGINX and NGINX Plus in [`vars/main.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/vars/main.yml)
220-
* Three new tags have been introduced -- `nginx_setup_license`, `nginx_install` and `nginx_check_support`.
226+
* Three new tags have been introduced -- `nginx_setup_license`, `nginx_enable` and `nginx_check_support`.
221227
* Add Alpine 3.12 to the list of supported platforms.
222228
* Remove Alpine 3.8 from the list of supported platforms.
223229
* Add NGINX Plus tests to TravisCI
@@ -301,7 +307,7 @@ FEATURES:
301307
* Add support to configure logrotate.
302308
* Add support for Ubuntu Focal.
303309
* Add support to configure SELinux.
304-
* Two new variables have been introduced -- `nginx_install` and `nginx_configure` -- to let you choose whether you want to install NGINX, configure NGINX, or both.
310+
* Two new variables have been introduced -- `nginx_enable` and `nginx_configure` -- to let you choose whether you want to install NGINX, configure NGINX, or both.
305311

306312
ENHANCEMENTS:
307313

defaults/main/main.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
---
2-
# Enable NGINX options -- `nginx_install` and `nginx_configure`.
3-
# Default is true.
4-
nginx_enable: true
5-
6-
# Install NGINX and NGINX modules.
2+
# Enable NGINX and NGINX modules.
73
# Variables for these options can be found below.
84
# Default is true.
9-
nginx_install: true
10-
11-
# Start NGINX service.
12-
# Default is true.
13-
nginx_start: true
5+
nginx_enable: true
146

157
# Print NGINX configuration file to terminal after executing playbook.
168
nginx_debug_output: false
@@ -26,13 +18,17 @@ nginx_type: opensource
2618
# For NGINX Plus and modules you'll need a wilcard like below (which installs plus-20 and modules)
2719
# nginx_version: "-20*"
2820

21+
# Start NGINX service.
22+
# Default is true.
23+
nginx_start: true
24+
2925
# Specify whether you want to maintain your version of NGINX, upgrade to the latest version, or remove NGINX.
30-
# Can be used with `nginx_version` to fine tune control on which version of NGINX is installed/used on each playbook execution.
31-
# Using 'present' will install the latest version (or 'nginx_version') of NGINX on a fresh install.
32-
# Using 'latest' will upgrade NGINX to the latest version (that matches your 'nginx_version') of NGINX on every playbook execution.
33-
# Using 'absent' will remove NGINX from your system.
34-
# Default is present.
35-
nginx_state: present
26+
# Can be used with `nginx_version` to fine tune control which version of NGINX is installed/used on each playbook execution.
27+
# Using 'install' will install the latest version (or 'nginx_version') of NGINX on a fresh install.
28+
# Using 'upgrade' will upgrade NGINX to the latest version (that matches your 'nginx_version') of NGINX on every playbook execution. Does not work on Alpine Linux.
29+
# Using 'uninstall' will remove NGINX from your system.
30+
# Default is install.
31+
nginx_setup: install
3632

3733
# Specify whether or not you want to manage the NGINX repositories.
3834
# Using 'true' will manage NGINX repositories.

defaults/main/selinux.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
22
# Set SELinux enforcing for NGINX (CentOS/Red Hat only) - you may need to open ports on your own
33
nginx_selinux: false
4+
45
# Enable enforcing mode if true. Permissive if false (audit only, no enforcing) globally (only works with nginx_selinux: true)
6+
57
nginx_selinux_enforcing: true
68
# List of TCP ports to add to http_port_t type (80 and 443 have this type already)
79
# nginx_selinux_tcp_ports:
810
# - 80
911
# - 443
12+
1013
# List of UDP ports to add to http_port_t type
1114
# nginx_selinux_udp_ports:
1215
# - 80

handlers/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
enabled: true
1111
when:
1212
- nginx_start | bool
13+
- nginx_state != "absent"
1314
- not ansible_check_mode | bool
1415
listen: (Handler) Run NGINX
1516

@@ -21,6 +22,7 @@
2122
ignore_errors: true
2223
check_mode: false
2324
changed_when: false
25+
when: nginx_state != "absent"
2426
listen: (Handler) Run NGINX
2527

2628
- name: (Handler) Print NGINX error if syntax check fails
@@ -30,6 +32,7 @@
3032
when:
3133
- config_check.stderr_lines is defined
3234
- config_check.rc != 0
35+
- nginx_state != "absent"
3336
listen: (Handler) Run NGINX
3437

3538
- name: (Handler) Start NGINX Amplify agent

molecule/default/converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
- 80
3333
- 443
3434
nginx_version: "{{ version }}"
35-
nginx_configure: false
3635
nginx_logrotate_conf_enable: true
3736
nginx_logrotate_conf:
3837
paths:

molecule/default/verify.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@
2323
uri:
2424
url: http://localhost
2525
status_code: 200
26+
27+
- name: Verify correct version of NGINX has been installed
28+
command: nginx -v
29+
args:
30+
chdir: "{{ ((ansible_facts['system'] | lower is not search('bsd')) | ternary('/etc/nginx', '/usr/local/sbin')) }}"
31+
changed_when: false
32+
register: version
33+
failed_when: version is not search('1.21.4')

molecule/uninstall/converge.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
tasks:
5+
- name: Uninstall NGINX
6+
include_role:
7+
name: ansible-role-nginx
8+
vars:
9+
nginx_setup: uninstall

molecule/uninstall/molecule.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
set -e
6+
yamllint .
7+
ansible-lint --force-color
8+
platforms:
9+
- name: alpine-3.12
10+
image: alpine:3.12
11+
dockerfile: ../common/Dockerfile.j2
12+
privileged: true
13+
volumes:
14+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
15+
command: "/sbin/init"
16+
- name: alpine-3.13
17+
image: alpine:3.13
18+
dockerfile: ../common/Dockerfile.j2
19+
privileged: true
20+
volumes:
21+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
22+
command: "/sbin/init"
23+
- name: alpine-3.14
24+
image: alpine:3.14
25+
dockerfile: ../common/Dockerfile.j2
26+
privileged: true
27+
volumes:
28+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
29+
command: "/sbin/init"
30+
- name: alpine-3.15
31+
image: alpine:3.15
32+
dockerfile: ../common/Dockerfile.j2
33+
privileged: true
34+
volumes:
35+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
36+
command: "/sbin/init"
37+
- name: amazonlinux-2
38+
image: amazonlinux:2
39+
dockerfile: ../common/Dockerfile.j2
40+
privileged: true
41+
volumes:
42+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
43+
command: "/usr/sbin/init"
44+
- name: centos-7
45+
image: centos:7
46+
dockerfile: ../common/Dockerfile.j2
47+
privileged: true
48+
volumes:
49+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
50+
command: "/usr/sbin/init"
51+
- name: centos-8
52+
image: centos:8
53+
dockerfile: ../common/Dockerfile.j2
54+
privileged: true
55+
volumes:
56+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
57+
command: "/usr/sbin/init"
58+
- name: debian-buster
59+
image: debian:buster-slim
60+
dockerfile: ../common/Dockerfile.j2
61+
privileged: true
62+
volumes:
63+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
64+
command: "/sbin/init"
65+
- name: debian-bullseye
66+
image: debian:bullseye-slim
67+
dockerfile: ../common/Dockerfile.j2
68+
privileged: true
69+
volumes:
70+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
71+
command: "/sbin/init"
72+
- name: ubuntu-bionic
73+
image: ubuntu:bionic
74+
dockerfile: ../common/Dockerfile.j2
75+
privileged: true
76+
volumes:
77+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
78+
command: "/sbin/init"
79+
- name: ubuntu-focal
80+
image: ubuntu:focal
81+
dockerfile: ../common/Dockerfile.j2
82+
privileged: true
83+
volumes:
84+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
85+
command: "/sbin/init"
86+
provisioner:
87+
name: ansible
88+
playbooks:
89+
prepare: prepare.yml
90+
converge: converge.yml
91+
verify: verify.yml

molecule/uninstall/prepare.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
tasks:
5+
- name: Install NGINX
6+
include_role:
7+
name: ansible-role-nginx

molecule/uninstall/verify.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
tasks:
5+
- name: Check if NGINX is installed
6+
package:
7+
name: nginx
8+
state: absent
9+
check_mode: true
10+
register: install
11+
failed_when: (install is changed) or (install is failed)

molecule/uninstall_plus/converge.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
tasks:
5+
- name: Uninstall NGINX
6+
include_role:
7+
name: ansible-role-nginx
8+
vars:
9+
nginx_setup: uninstall
10+
nginx_type: plus
11+
nginx_setup_license: false

molecule/uninstall_plus/molecule.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
set -e
6+
yamllint .
7+
ansible-lint --force-color
8+
platforms:
9+
- name: alpine-3.11
10+
image: alpine:3.11
11+
dockerfile: ../common/Dockerfile.j2
12+
privileged: true
13+
volumes:
14+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
15+
command: "/sbin/init"
16+
- name: alpine-3.12
17+
image: alpine:3.12
18+
dockerfile: ../common/Dockerfile.j2
19+
privileged: true
20+
volumes:
21+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
22+
command: "/sbin/init"
23+
- name: alpine-3.13
24+
image: alpine:3.13
25+
dockerfile: ../common/Dockerfile.j2
26+
privileged: true
27+
volumes:
28+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
29+
command: "/sbin/init"
30+
- name: alpine-3.14
31+
image: alpine:3.14
32+
dockerfile: ../common/Dockerfile.j2
33+
privileged: true
34+
volumes:
35+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
36+
command: "/sbin/init"
37+
- name: amazonlinux-2
38+
image: amazonlinux:2
39+
dockerfile: ../common/Dockerfile.j2
40+
privileged: true
41+
volumes:
42+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
43+
command: "/usr/sbin/init"
44+
- name: centos-7
45+
image: centos:7
46+
dockerfile: ../common/Dockerfile.j2
47+
privileged: true
48+
volumes:
49+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
50+
command: "/usr/sbin/init"
51+
- name: centos-8
52+
image: centos:8
53+
dockerfile: ../common/Dockerfile.j2
54+
privileged: true
55+
volumes:
56+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
57+
command: "/usr/sbin/init"
58+
- name: debian-buster
59+
image: debian:buster-slim
60+
dockerfile: ../common/Dockerfile.j2
61+
privileged: true
62+
volumes:
63+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
64+
command: "/sbin/init"
65+
- name: debian-bullseye
66+
image: debian:bullseye-slim
67+
dockerfile: ../common/Dockerfile.j2
68+
privileged: true
69+
volumes:
70+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
71+
command: "/sbin/init"
72+
- name: ubuntu-bionic
73+
image: ubuntu:bionic
74+
dockerfile: ../common/Dockerfile.j2
75+
privileged: true
76+
volumes:
77+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
78+
command: "/sbin/init"
79+
- name: ubuntu-focal
80+
image: ubuntu:focal
81+
dockerfile: ../common/Dockerfile.j2
82+
privileged: true
83+
volumes:
84+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
85+
command: "/sbin/init"
86+
provisioner:
87+
name: ansible
88+
playbooks:
89+
prepare: prepare.yml
90+
converge: converge.yml
91+
verify: verify.yml

0 commit comments

Comments
 (0)