Skip to content

Commit ac5453e

Browse files
authored
Allow NGINX version downgrades (#475)
1 parent 5f1fc18 commit ac5453e

File tree

13 files changed

+181
-3
lines changed

13 files changed

+181
-3
lines changed

.github/workflows/molecule.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
matrix:
2121
scenario:
2222
- default
23+
- downgrade
2324
- module
2425
- plus
2526
- source

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ BREAKING CHANGES:
66

77
* 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`.
88
* `nginx_install` variable is no more. Use `nginx_enable` instead.
9+
* Ansible core `2.12` is now a minimum requirement for the role.
910

1011
FEATURES:
1112

12-
Pin repository data when installing NGINX OSS on Alpine and Debian distributions.
13+
* Pin repository data when installing NGINX OSS on Alpine and Debian distributions.
14+
* You can now downgrade versions of NGINX and switch from stable to mainline and viceversa. You will need to specify the NGINX branch and version you wish to install when tweaking versions.
1315

1416
ENHANCEMENTS:
1517

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you wish to install NGINX Plus using this role, you will need to obtain an NG
1818

1919
### Ansible
2020

21-
* This role is developed and tested with [maintained](https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html) versions of Ansible core (above `2.11`).
21+
* This role is developed and tested with [maintained](https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html) versions of Ansible core (above `2.12`).
2222
* When using Ansible core, you will also need to install the following collections:
2323

2424
```yaml

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ galaxy_info:
88

99
license: Apache License, Version 2.0
1010

11-
min_ansible_version: 2.11
11+
min_ansible_version: 2.12
1212

1313
platforms:
1414
- name: Alpine

molecule/downgrade/converge.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
pre_tasks:
5+
- name: Set repo if Alpine
6+
set_fact:
7+
version: "=1.20.2-r1"
8+
when: ansible_facts['os_family'] == "Alpine"
9+
- name: Set repo if Debian
10+
set_fact:
11+
version: "=1.20.2-1~{{ ansible_facts['distribution_release'] }}"
12+
when: ansible_facts['os_family'] == "Debian"
13+
- name: Set repo if Red Hat
14+
set_fact:
15+
version: "-1.20.2-1.{{ (ansible_facts['distribution']=='Amazon') | ternary('amzn2', ('el' + ansible_facts['distribution_major_version'] | string)) }}.ngx"
16+
when: ansible_facts['os_family'] == "RedHat"
17+
tasks:
18+
- name: Install NGINX
19+
include_role:
20+
name: ansible-role-nginx
21+
vars:
22+
nginx_version: "{{ version }}"
23+
nginx_branch: stable

molecule/downgrade/molecule.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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: amazonlinux-2
31+
image: amazonlinux:2
32+
dockerfile: ../common/Dockerfile.j2
33+
privileged: true
34+
volumes:
35+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
36+
command: "/usr/sbin/init"
37+
- name: centos-7
38+
image: centos:7
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-8
45+
image: centos:8
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: debian-buster
52+
image: debian:buster-slim
53+
dockerfile: ../common/Dockerfile.j2
54+
privileged: true
55+
volumes:
56+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
57+
command: "/sbin/init"
58+
- name: debian-bullseye
59+
image: debian:bullseye-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: ubuntu-bionic
66+
image: ubuntu:bionic
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-focal
73+
image: ubuntu:focal
74+
dockerfile: ../common/Dockerfile.j2
75+
privileged: true
76+
volumes:
77+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
78+
command: "/sbin/init"
79+
provisioner:
80+
name: ansible
81+
playbooks:
82+
prepare: prepare.yml
83+
converge: converge.yml
84+
verify: verify.yml

molecule/downgrade/prepare.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
pre_tasks:
5+
- name: Set repo if Alpine
6+
set_fact:
7+
version: "=1.21.4-r1"
8+
when: ansible_facts['os_family'] == "Alpine"
9+
- name: Set repo if Debian
10+
set_fact:
11+
version: "=1.21.4-1~{{ ansible_facts['distribution_release'] }}"
12+
when: ansible_facts['os_family'] == "Debian"
13+
- name: Set repo if Red Hat
14+
set_fact:
15+
version: "-1.21.4-1.{{ (ansible_facts['distribution']=='Amazon') | ternary('amzn2', ('el' + ansible_facts['distribution_major_version'] | string)) }}.ngx"
16+
when: ansible_facts['os_family'] == "RedHat"
17+
- name: Enable NGINX @CentOS-AppStream dnf modules
18+
shell:
19+
args:
20+
cmd: dnf module info nginx | grep -q 'Stream.*\[e\]' && echo -n ENABLED || dnf module enable -y nginx # noqa command-instead-of-module
21+
register: dnf_module_enable
22+
changed_when: dnf_module_enable.stdout != 'ENABLED'
23+
when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('8', '==')
24+
tasks:
25+
- name: Install NGINX
26+
include_role:
27+
name: ansible-role-nginx
28+
vars:
29+
nginx_version: "{{ version }}"

molecule/downgrade/verify.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
tasks:
5+
- name: Check if NGINX is installed
6+
package:
7+
name: nginx
8+
state: present
9+
check_mode: true
10+
register: install
11+
failed_when: (install is changed) or (install is failed)
12+
13+
- name: Check if NGINX service is running
14+
service:
15+
name: nginx
16+
state: started
17+
enabled: true
18+
check_mode: true
19+
register: service
20+
failed_when: (service is changed) or (service is failed)
21+
22+
- name: Verify NGINX is up and running
23+
uri:
24+
url: http://localhost
25+
status_code: 200
26+
27+
# - name: Verify NGINX has been downgraded
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.3')

molecule/upgrade/molecule.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ platforms:
5858
provisioner:
5959
name: ansible
6060
playbooks:
61+
prepare: prepare.yml
6162
converge: converge.yml
6263
verify: verify.yml

tasks/opensource/install-debian.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@
2626
apt:
2727
name: "nginx{{ nginx_version | default('') }}"
2828
state: "{{ nginx_state }}"
29+
update_cache: true
30+
allow_downgrade: true
2931
ignore_errors: "{{ ansible_check_mode }}"
3032
notify: (Handler) Run NGINX

tasks/opensource/install-redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
name: "nginx{{ nginx_version | default('') }}"
1818
state: "{{ nginx_state }}"
1919
update_cache: true
20+
allow_downgrade: true
2021
ignore_errors: "{{ ansible_check_mode }}"
2122
notify: (Handler) Run NGINX

tasks/plus/install-debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
name: "nginx-plus{{ nginx_version | default('') }}"
2626
state: "{{ nginx_state }}"
2727
update_cache: true
28+
allow_downgrade: true
2829
ignore_errors: "{{ ansible_check_mode }}"
2930
when: nginx_license_status is not defined
3031
notify: (Handler) Run NGINX

tasks/plus/install-redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
name: "nginx-plus{{ nginx_version | default('') }}"
1919
state: "{{ nginx_state }}"
2020
update_cache: true
21+
allow_downgrade: true
2122
ignore_errors: "{{ ansible_check_mode }}"
2223
when: nginx_license_status is not defined
2324
notify: (Handler) Run NGINX

0 commit comments

Comments
 (0)