Skip to content

Commit d152466

Browse files
committed
Add distribution Molecule scenario
1 parent 35ad84e commit d152466

File tree

9 files changed

+285
-10
lines changed

9 files changed

+285
-10
lines changed

.github/workflows/molecule.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
matrix:
2525
scenario:
2626
- default
27+
- distribution
2728
- downgrade
2829
- downgrade-plus
2930
- plus

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ENHANCEMENTS:
3131

3232
BUG FIXES:
3333

34+
* Fix the NGINX installation process when installing NGINX from a distribution's package repository in CentOS/RHEL 7 based distributions.
3435
* Fix an issue when installing the GeoIP2 module on an UBI 7 container where the the `libmaxminddb` package dependency might not be available via `yum` (if it's not available, `libmaxminddb` is installed from an external source).
3536
* GitHub actions should now correctly skip \*plus\* scenarios only when the NGINX Plus license secrets are not present.
3637
* Update the versions of the various packages required to build NGINX from source. The version of `zlib` listed in the role was no longer available.
@@ -44,6 +45,7 @@ TESTS:
4445
* Explicitly test some distributions using `aarch64` and `s390x` as the Molecule platform. This should ensure the role works as intended across the various architectures that are officially supported.
4546
* Combine the `module` Molecule scenario with the `default` scenario.
4647
* Add `stable` Molecule scenario.
48+
* Add `distribution` Molecule scenario.
4749
* Replace underscores with dashes in Molecule scenario names to improve naming consistency across the role.
4850

4951
## 0.23.2 (September 28, 2022)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Working functional playbook examples can be found in the **[`molecule/`](https:/
191191
| Name | Description |
192192
| ---- | ----------- |
193193
| **[`default/converge.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/molecule/default/converge.yml)** | Install a specific version of NGINX, install various NGINX supported modules, tweak systemd and set up logrotate |
194+
| **[`distribution/converge.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/molecule/distribution/converge.yml)** | Install NGINX from the distribution's package repository instead of NGINX's package repository |
194195
| **[`downgrade/converge.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/molecule/downgrade/converge.yml)** | Downgrade to a specific version of NGINX |
195196
| **[`downgrade-plus/converge.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/molecule/downgrade-plus/converge.yml)** | Downgrade to a specific version of NGINX Plus |
196197
| **[`plus/converge.yml`](https://github.com/nginxinc/ansible-role-nginx/blob/main/molecule/plus/converge.yml)** | Install NGINX Plus and various NGINX Plus supported modules |

defaults/main/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ nginx_setup: install
3838
nginx_manage_repo: true
3939

4040
# Specify repository origin for NGINX Open Source.
41-
# Options are 'nginx_repository', 'source' or 'os_repository'.
4241
# Only works if 'nginx_type' is set to 'opensource'.
42+
# Options are 'nginx_repository', 'source' or 'os_repository'.
43+
# When using 'os_repository' on CentOS/RHEL 7 based systems, you will also need to install the EPEL repository (see the 'nginx_install_epel_release' variable below).
4344
# Default is nginx_repository.
4445
nginx_install_from: nginx_repository
4546

@@ -90,7 +91,7 @@ nginx_setup_license: true
9091
# Default is true.
9192
nginx_remove_license: true
9293

93-
# Specify whether or not you want this role to install the EPEL package when installing certain NGINX Plus modules.
94+
# Specify whether or not you want this role to install the EPEL package when installing NGINX OSS in some distributions and some NGINX OSS/Plus modules.
9495
# Using 'true' will install EPEL.
9596
# Using 'false' will not install EPEL.
9697
# Default is true.

molecule/distribution/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: Install NGINX
6+
ansible.builtin.include_role:
7+
name: ansible-role-nginx
8+
vars:
9+
nginx_install_from: os_repository

molecule/distribution/molecule.yml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
set -e
6+
ansible-lint --force-color
7+
platforms: # The RHEL UBI 7 image fails to install some NGINX dependencies when installing NGINX from EPEL. The role works as expected when targeting a RHEL 7 VM instead.
8+
- name: almalinux-8
9+
image: almalinux:8
10+
dockerfile: ../common/Dockerfile.j2
11+
privileged: true
12+
cgroupns_mode: host
13+
volumes:
14+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
15+
command: /usr/sbin/init
16+
- name: almalinux-9
17+
image: almalinux:9
18+
dockerfile: ../common/Dockerfile.j2
19+
privileged: true
20+
cgroupns_mode: host
21+
volumes:
22+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
23+
command: /usr/sbin/init
24+
- name: alpine-3.14
25+
image: alpine:3.14
26+
dockerfile: ../common/Dockerfile.j2
27+
privileged: true
28+
cgroupns_mode: host
29+
volumes:
30+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
31+
command: /sbin/init
32+
- name: alpine-3.15
33+
image: alpine:3.15
34+
dockerfile: ../common/Dockerfile.j2
35+
privileged: true
36+
cgroupns_mode: host
37+
volumes:
38+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
39+
command: /sbin/init
40+
- name: alpine-3.16
41+
image: alpine:3.16
42+
dockerfile: ../common/Dockerfile.j2
43+
privileged: true
44+
cgroupns_mode: host
45+
volumes:
46+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
47+
command: /sbin/init
48+
- name: alpine-3.17
49+
image: alpine:3.17
50+
dockerfile: ../common/Dockerfile.j2
51+
privileged: true
52+
cgroupns_mode: host
53+
volumes:
54+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
55+
command: /sbin/init
56+
- name: amazonlinux-2
57+
image: amazonlinux:2
58+
platform: amd64
59+
dockerfile: ../common/Dockerfile.j2
60+
privileged: true
61+
cgroupns_mode: host
62+
volumes:
63+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
64+
command: /usr/sbin/init
65+
- name: centos-7
66+
image: centos:7
67+
platform: amd64
68+
dockerfile: ../common/Dockerfile.j2
69+
privileged: true
70+
cgroupns_mode: host
71+
volumes:
72+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
73+
command: /usr/sbin/init
74+
- name: debian-bullseye
75+
image: debian:bullseye-slim
76+
dockerfile: ../common/Dockerfile.j2
77+
privileged: true
78+
cgroupns_mode: host
79+
volumes:
80+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
81+
command: /sbin/init
82+
- name: oraclelinux-7
83+
image: oraclelinux:7
84+
platform: amd64
85+
dockerfile: ../common/Dockerfile.j2
86+
privileged: true
87+
cgroupns_mode: host
88+
volumes:
89+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
90+
command: /usr/sbin/init
91+
- name: oraclelinux-8
92+
image: oraclelinux:8
93+
dockerfile: ../common/Dockerfile.j2
94+
privileged: true
95+
cgroupns_mode: host
96+
volumes:
97+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
98+
command: /usr/sbin/init
99+
- name: oraclelinux-9
100+
image: oraclelinux:9
101+
dockerfile: ../common/Dockerfile.j2
102+
privileged: true
103+
cgroupns_mode: host
104+
volumes:
105+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
106+
command: /usr/sbin/init
107+
- name: rhel-8
108+
image: redhat/ubi8:8.7
109+
dockerfile: ../common/Dockerfile.j2
110+
privileged: true
111+
cgroupns_mode: host
112+
volumes:
113+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
114+
command: /usr/sbin/init
115+
- name: rhel-9
116+
image: redhat/ubi9:9.1.0
117+
dockerfile: ../common/Dockerfile.j2
118+
privileged: true
119+
cgroupns_mode: host
120+
volumes:
121+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
122+
command: /usr/sbin/init
123+
- name: rockylinux-8
124+
image: rockylinux:8
125+
dockerfile: ../common/Dockerfile.j2
126+
privileged: true
127+
cgroupns_mode: host
128+
volumes:
129+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
130+
command: /usr/sbin/init
131+
- name: rockylinux-9
132+
image: rockylinux:9.0.20220720
133+
dockerfile: ../common/Dockerfile.j2
134+
privileged: true
135+
cgroupns_mode: host
136+
volumes:
137+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
138+
command: /usr/sbin/init
139+
- name: sles15
140+
image: registry.suse.com/bci/bci-base:15.4
141+
platform: amd64
142+
dockerfile: ../common/Dockerfile.j2
143+
privileged: true
144+
cgroupns_mode: host
145+
volumes:
146+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
147+
command: /usr/sbin/init
148+
- name: ubuntu-bionic
149+
image: ubuntu:bionic
150+
dockerfile: ../common/Dockerfile.j2
151+
privileged: true
152+
cgroupns_mode: host
153+
volumes:
154+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
155+
command: /sbin/init
156+
- name: ubuntu-focal
157+
image: ubuntu:focal
158+
dockerfile: ../common/Dockerfile.j2
159+
privileged: true
160+
cgroupns_mode: host
161+
volumes:
162+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
163+
command: /sbin/init
164+
- name: ubuntu-jammy
165+
image: ubuntu:jammy
166+
dockerfile: ../common/Dockerfile.j2
167+
privileged: true
168+
cgroupns_mode: host
169+
volumes:
170+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
171+
command: /sbin/init
172+
provisioner:
173+
name: ansible
174+
log: true
175+
playbooks:
176+
converge: converge.yml
177+
verify: verify.yml

molecule/distribution/verify.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
tasks:
5+
- name: Check if NGINX is installed
6+
ansible.builtin.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+
ansible.builtin.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+
ansible.builtin.uri:
24+
url: http://localhost
25+
status_code: 200
26+
when: ansible_facts['distribution'] != 'Alpine'
27+
28+
- name: Verify NGINX is up and running
29+
ansible.builtin.uri:
30+
url: http://localhost
31+
status_code: 404
32+
when: ansible_facts['distribution'] == 'Alpine'
33+
34+
- name: Verify NGINX is up and running
35+
ansible.builtin.uri:
36+
url: http://localhost
37+
status_code: 503
38+
when: ansible_facts['distribution'] == 'Suse'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
- name: (CentOS/RHEL 7) Set up the EPEL repository
3+
when:
4+
- ansible_facts['distribution'] in ["CentOS", "RedHat"]
5+
- ansible_facts['distribution_major_version'] is version('7', '==')
6+
- nginx_install_epel_release | bool
7+
block:
8+
- name: (CentOS/RHEL 7) Import the EPEL repository GPG key
9+
ansible.builtin.rpm_key:
10+
state: present
11+
key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ((ansible_facts['distribution'] == 'Amazon') | ternary('7', ansible_facts['distribution_major_version'])) }}
12+
13+
- name: (CentOS/RHEL 7) Install the EPEL repository
14+
ansible.builtin.yum:
15+
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ((ansible_facts['distribution'] == 'Amazon') | ternary('7', ansible_facts['distribution_major_version'])) }}.noarch.rpm
16+
17+
- name: (Oracle Linux 7) Install the EPEL repository
18+
ansible.builtin.yum:
19+
name: oracle-epel-release-el7
20+
when:
21+
- ansible_facts['distribution'] == "OracleLinux"
22+
- ansible_facts['distribution_major_version'] is version('7', '==')
23+
- nginx_install_epel_release | bool
24+
25+
- name: (CentOS) Remove the nodocs flag from yum.conf
26+
ansible.builtin.lineinfile:
27+
path: /etc/yum.conf
28+
state: absent
29+
line: tsflags=nodocs
30+
when:
31+
- ansible_facts['distribution'] == "CentOS"
32+
- ansible_facts['distribution_major_version'] is version('7', '==')
33+
34+
- name: (Amazon Linux) {{ nginx_setup | capitalize }} NGINX from Amazon's extras package repository
35+
ansible.builtin.command: amazon-linux-extras {{ (nginx_setup == 'uninstall') | ternary('remove', 'install') }} -y nginx1
36+
args:
37+
creates: "{{ (nginx_setup == 'uninstall') | ternary(omit, '/sbin/nginx') }}"
38+
removes: "{{ (nginx_setup == 'uninstall') | ternary('/sbin/nginx', omit) }}"
39+
when:
40+
- ansible_facts['distribution'] == "Amazon"
41+
- nginx_state == "absent"
42+
notify: (Handler) Run NGINX
43+
44+
- name: "{{ nginx_setup | capitalize }} NGINX from the distribution's package repository"
45+
ansible.builtin.package:
46+
name: nginx{{ nginx_version | default('') }}
47+
state: "{{ nginx_state }}"
48+
when: ansible_facts['distribution'] != "Amazon"
49+
notify: (Handler) Run NGINX

tasks/opensource/install-oss.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
- name: "{{ nginx_setup | capitalize }} NGINX in Linux systems"
33
when: ansible_facts['system'] | lower is not search('bsd')
44
block:
5-
- name: "{{ nginx_setup | capitalize }} NGINX from repository"
5+
- name: "{{ nginx_setup | capitalize }} NGINX from the official package repository"
66
ansible.builtin.include_tasks: "{{ role_path }}/tasks/opensource/install-{{ ansible_facts['os_family'] | lower }}.yml"
77
when: nginx_install_from == "nginx_repository"
88

9+
- name: "{{ nginx_setup | capitalize }} NGINX from the distribution's package repository"
10+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/opensource/install-distribution.yml"
11+
when: nginx_install_from == "os_repository"
12+
913
- name: "{{ nginx_setup | capitalize }} NGINX from source"
1014
ansible.builtin.include_tasks: "{{ role_path }}/tasks/opensource/install-source.yml"
1115
when: nginx_install_from == "source"
1216

13-
- name: "{{ nginx_setup | capitalize }} NGINX from package"
14-
ansible.builtin.package:
15-
name: nginx{{ nginx_version | default('') }}
16-
state: "{{ nginx_state }}"
17-
when: nginx_install_from == "os_repository"
18-
notify: (Handler) Run NGINX
19-
2017
- name: "{{ nginx_setup | capitalize }} NGINX in Unix systems"
2118
ansible.builtin.include_tasks: "{{ role_path }}/tasks/opensource/install-bsd.yml"
2219
when: ansible_facts['system'] | lower is search('bsd')

0 commit comments

Comments
 (0)