Skip to content

Commit 058cb57

Browse files
authored
Standardize code from dot to array notation (#584)
1 parent 1ba553b commit 058cb57

21 files changed

+147
-157
lines changed

CHANGELOG.md

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

3-
## 0.23.3 (Unreleased)
3+
## 0.24.0 (Unreleased)
44

55
BREAKING CHANGES:
66

@@ -27,6 +27,8 @@ FEATURES:
2727

2828
ENHANCEMENTS:
2929

30+
* Standardize code from dot to array notation to keep in with the standards set by the other roles in the Ansible NGINX core collection.
31+
* Bump the minimum version of Ansible core required to run the role to `2.12` (`2.11` is no longer supported by Ansible).
3032
* Improve validation of supported distributions when installing NGINX from the official repository.
3133
* Bump the Ansible `community.general` collection to `6.2.0`, `community.crypto` collection to `2.10.0` and `community.docker` collection to `3.4.0`.
3234
* Use the official GitHub repositories as the source for the various packages required to compile NGINX OSS from source.

handlers/main.yml

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

@@ -22,18 +22,18 @@
2222
ignore_errors: true
2323
check_mode: false
2424
changed_when: false
25-
when: nginx_state != "absent"
25+
when: nginx_state != 'absent'
2626
listen: (Handler) Run NGINX
2727

2828
- name: (Handler) Print NGINX error if syntax check fails
2929
ansible.builtin.debug:
3030
var: config_check.stderr_lines
31-
failed_when: config_check.rc != 0
31+
failed_when: config_check['rc'] != 0
3232
when:
33-
- config_check.stderr_lines is defined
34-
- config_check.stderr_lines != []
35-
- config_check.rc != 0
36-
- nginx_state != "absent"
33+
- config_check['stderr_lines'] is defined
34+
- config_check['stderr_lines'] != []
35+
- config_check['rc'] != 0
36+
- nginx_state != 'absent'
3737
listen: (Handler) Run NGINX
3838

3939
- name: (Handler) Start NGINX Amplify agent

meta/main.yml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
---
22
galaxy_info:
33
author: nginxinc
4-
description: Official Ansible role for NGINX
4+
description: Official Ansible role for installing NGINX
55
role_name: nginx
66
company: F5, Inc.
77

88
license: Apache License, Version 2.0
99

10-
min_ansible_version: "2.12"
10+
min_ansible_version: '2.12'
1111

1212
platforms:
1313
- name: Alpine
14-
versions:
15-
- all
14+
versions: [all]
1615
- name: Amazon Linux 2
17-
versions:
18-
- all
16+
versions: [all]
1917
- name: Debian
20-
versions:
21-
- bullseye
18+
versions: [bullseye]
2219
- name: EL
23-
versions:
24-
- "7"
25-
- "8"
26-
- "9"
20+
versions: ['7', '8', '9']
2721
- name: FreeBSD
28-
versions:
29-
- "12.1"
22+
versions: ['12.1']
3023
- name: Ubuntu
31-
versions:
32-
- bionic
33-
- focal
34-
- impish
35-
- jammy
24+
versions: [bionic, focal, impish, jammy]
3625
- name: SLES
37-
versions:
38-
- "12"
39-
- "15"
26+
versions: ['12', '15']
4027

4128
galaxy_tags:
4229
- nginx

molecule/default/converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
name: ansible-role-nginx
88
vars:
99
nginx_modules:
10-
- brotli
1110
- geoip
1211
- image-filter
1312
- njs

tasks/amplify/setup-redhat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: (Amazon Linux/CentOS/RHEL) Add NGINX Amplify agent repository
33
ansible.builtin.yum_repository:
44
name: nginx-amplify
5-
baseurl: https://packages.amplify.nginx.com/{{ (ansible_facts['distribution_major_version'] == "7") | ternary('', 'py3/') }}{{ (ansible_facts['distribution'] == "Amazon") | ternary('amzn', 'centos') }}/$releasever/$basearch/
5+
baseurl: https://packages.amplify.nginx.com/{{ (ansible_facts['distribution_major_version'] is version('7', '==')) | ternary('', 'py3/') }}{{ (ansible_facts['distribution'] == 'Amazon') | ternary('amzn', 'centos') }}/$releasever/$basearch/
66
description: NGINX Amplify Agent
77
enabled: true
88
gpgcheck: true

tasks/config/setup-logrotate.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
- name: (Alpine Linux) Install logrotate
33
community.general.apk:
44
name: logrotate
5-
when: ansible_facts['os_family'] == "Alpine"
5+
when: ansible_facts['os_family'] == 'Alpine'
66

77
- name: (Debian/Ubuntu) Install logrotate
88
ansible.builtin.apt:
99
name: logrotate
1010
state: present
11-
when: ansible_facts['os_family'] == "Debian"
11+
when: ansible_facts['os_family'] == 'Debian'
1212

1313
- name: (Amazon Linux/CentOS/Oracle Linux/RHEL) Install logrotate
1414
ansible.builtin.yum:
1515
name: logrotate
1616
state: present
17-
when: ansible_facts['os_family'] == "RedHat"
17+
when: ansible_facts['os_family'] == 'RedHat'
1818

1919
- name: (SLES) Install Logrotate
2020
community.general.zypper:
2121
name: logrotate
2222
state: present
23-
when: ansible_facts['os_family'] == "Suse"
23+
when: ansible_facts['os_family'] == 'Suse'
2424

2525
- name: Create logrotate config
2626
ansible.builtin.template:

tasks/keys/setup-keys.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: (Alpine Linux) Set up signing key
3-
when: ansible_facts['os_family'] == "Alpine"
3+
when: ansible_facts['os_family'] == 'Alpine'
44
block:
55
- name: (Alpine Linux) Set up NGINX signing key URL
66
ansible.builtin.set_fact:
@@ -15,14 +15,14 @@
1515
- name: (Debian/Red Hat/SLES OSs) Set up NGINX signing key URL
1616
ansible.builtin.set_fact:
1717
keysite: "{{ nginx_signing_key | default(nginx_default_signing_key_pgp) }}"
18-
when: ansible_facts['os_family'] != "Alpine"
18+
when: ansible_facts['os_family'] != 'Alpine'
1919

2020
- name: (Debian/Ubuntu) Add NGINX signing key
2121
ansible.builtin.apt_key:
2222
id: 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
2323
keyring: /usr/share/keyrings/nginx-archive-keyring.gpg
2424
url: "{{ keysite }}"
25-
when: ansible_facts['os_family'] == "Debian"
25+
when: ansible_facts['os_family'] == 'Debian'
2626

2727
- name: (Red Hat/SLES OSs) Add NGINX signing key
2828
ansible.builtin.rpm_key:

tasks/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
- name: Set up prerequisites
77
ansible.builtin.include_tasks: "{{ role_path }}/tasks/prerequisites/prerequisites.yml"
8-
when: nginx_state != "absent"
8+
when: nginx_state != 'absent'
99
tags: nginx_prerequisites
1010

1111
- name: Set up signing keys
1212
ansible.builtin.include_tasks: "{{ role_path }}/tasks/keys/setup-keys.yml"
13-
when: (nginx_enable | bool and nginx_install_from == "nginx_repository")
13+
when: (nginx_enable | bool and nginx_install_from == 'nginx_repository')
1414
or nginx_amplify_enable | bool
1515
tags: nginx_key
1616

@@ -20,19 +20,19 @@
2020
block:
2121
- name: "{{ nginx_setup | capitalize }} NGINX Open Source"
2222
ansible.builtin.include_tasks: "{{ role_path }}/tasks/opensource/install-oss.yml"
23-
when: nginx_type == "opensource"
23+
when: nginx_type == 'opensource'
2424
tags: nginx_install_oss
2525

2626
- name: Set up NGINX Plus license
2727
ansible.builtin.include_tasks: "{{ role_path }}/tasks/plus/setup-license.yml"
2828
when:
29-
- nginx_type == "plus"
29+
- nginx_type == 'plus'
3030
- nginx_setup_license | bool
3131
tags: nginx_setup_license
3232

3333
- name: "{{ nginx_setup | capitalize }} NGINX Plus"
3434
ansible.builtin.include_tasks: "{{ role_path }}/tasks/plus/install-{{ ansible_facts['os_family'] | lower }}.yml"
35-
when: nginx_type == "plus"
35+
when: nginx_type == 'plus'
3636
tags: nginx_install_plus
3737

3838
- name: "{{ nginx_setup | capitalize }} NGINX dynamic modules"
@@ -45,14 +45,14 @@
4545
- name: Remove NGINX Plus license
4646
ansible.builtin.include_tasks: "{{ role_path }}/tasks/plus/remove-license.yml"
4747
when:
48-
- nginx_type == "plus"
48+
- nginx_type == 'plus'
4949
- nginx_remove_license | bool
5050
tags: nginx_remove_license
5151

5252
- name: Modify systemd parameters
5353
ansible.builtin.include_tasks: "{{ role_path }}/tasks/config/modify-systemd.yml"
5454
when:
55-
- ansible_facts['service_mgr'] == "systemd"
55+
- ansible_facts['service_mgr'] == 'systemd'
5656
- nginx_service_modify | bool
5757
tags: nginx_modify_systemd
5858

@@ -64,14 +64,14 @@
6464
when:
6565
- nginx_enable | bool
6666
- nginx_debug_output | bool
67-
- nginx_state != "absent"
67+
- nginx_state != 'absent'
6868
tags: nginx_debug_output
6969

7070
- name: Configure logrotate for NGINX
7171
ansible.builtin.include_tasks: "{{ role_path }}/tasks/config/setup-logrotate.yml"
7272
when:
7373
- nginx_logrotate_conf_enable | bool
74-
- nginx_state != "absent"
74+
- nginx_state != 'absent'
7575
tags: nginx_logrotate_config
7676

7777
- name: Install NGINX Amplify

tasks/modules/install-modules.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
- name: (Amazon Linux/RHEL 7) Install libmaxminddb
2222
ansible.builtin.yum:
2323
name: https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/libmaxminddb-1.2.0-6.el7.x86_64.rpm
24-
when: '"libmaxminddb" not in packages.results'
24+
when: "'libmaxminddb' not in packages['results']"
2525

2626
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Install GeoIP2 and/or OpenTracing EPEL dependency
2727
when:
2828
- ansible_facts['os_family'] == "RedHat"
29-
- ('"opentracing" in nginx_modules')
29+
- ('opentracing' in nginx_modules)
3030
- nginx_install_epel_release | bool
3131
block:
3232
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Import EPEL GPG key
@@ -43,27 +43,27 @@
4343
name: nginx-plus-module-ndk
4444
when:
4545
- nginx_type == 'plus'
46-
- ansible_facts['os_family'] == "Alpine"
46+
- ansible_facts['os_family'] == 'Alpine'
4747
- ansible_facts['distribution_version'] | regex_search('^[0-9]+\\.[0-9]+') is version('3.17', '==')
48-
- ('"encrypted-sessions" in nginx_modules') or ('"lua" in nginx_modules') or ('"set-misc" in nginx_modules')
48+
- ('encrypted-sessions' in nginx_modules) or ('lua' in nginx_modules) or ('set-misc' in nginx_modules)
4949

5050
- name: Install NGINX modules
5151
ansible.builtin.package:
52-
name: "nginx-{{ (nginx_type == 'plus') | ternary('plus-', '') }}module-{{ item.name | default(item) }}\
53-
{{ (nginx_repository is not defined and ansible_facts['os_family'] == 'Alpine' and nginx_type != 'plus') | ternary('@nginx', '') }}{{ item.version | default('') }}"
54-
state: "{{ item.state | default('present') }}"
52+
name: "nginx-{{ (nginx_type == 'plus') | ternary('plus-', '') }}module-{{ item['name'] | default(item) }}\
53+
{{ (nginx_repository is not defined and ansible_facts['os_family'] == 'Alpine' and nginx_type != 'plus') | ternary('@nginx', '') }}{{ item['version'] | default('') }}"
54+
state: "{{ item['state'] | default('present') }}"
5555
loop: "{{ nginx_modules }}"
5656
when:
57-
- (item.name | default(item) in nginx_modules_list and nginx_type == 'opensource')
58-
or (item.name | default(item) in nginx_plus_modules_list and nginx_type == 'plus')
59-
- not (item.name | default(item) == "brotli")
60-
or not (ansible_facts['os_family'] == "Suse" and ansible_facts['distribution_major_version'] is version('12', '=='))
61-
- not (item.name | default(item) == "geoip")
62-
or not ((ansible_facts['os_family'] == "FreeBSD")
63-
or (ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('8', '>=')))
64-
- not (item.name | default(item) == "geoip2")
65-
or not (ansible_facts['os_family'] == "Suse")
66-
- not (item.name | default(item) == "lua")
67-
or not (ansible_facts['architecture'] == "s390x")
68-
- not (item.name | default(item) == "opentracing")
69-
or not (ansible_facts['os_family'] == "Suse" and ansible_facts['distribution_major_version'] is version('12', '=='))
57+
- (item['name'] | default(item) in nginx_modules_list and nginx_type == 'opensource')
58+
or (item['name'] | default(item) in nginx_plus_modules_list and nginx_type == 'plus')
59+
- not (item['name'] | default(item) == 'brotli')
60+
or not (ansible_facts['os_family'] == 'Suse' and ansible_facts['distribution_major_version'] is version('12', '=='))
61+
- not (item['name'] | default(item) == "geoip")
62+
or not ((ansible_facts['os_family'] == 'FreeBSD')
63+
or (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('8', '>=')))
64+
- not (item['name'] | default(item) == 'geoip2')
65+
or not (ansible_facts['os_family'] == 'Suse')
66+
- not (item['name'] | default(item) == 'lua')
67+
or not (ansible_facts['architecture'] == 's390x')
68+
- not (item['name'] | default(item) == 'opentracing')
69+
or not (ansible_facts['os_family'] == 'Suse' and ansible_facts['distribution_major_version'] is version('12', '=='))

tasks/opensource/install-bsd.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
- name: (FreeBSD) Update ports
33
when:
4-
- ansible_facts['system'] == "FreeBSD"
4+
- ansible_facts['system'] == 'FreeBSD'
55
- nginx_bsd_update_ports | bool
66
block:
77
- name: (FreeBSD) Fetch ports
8-
ansible.builtin.command: portsnap fetch --interactive
9-
args:
8+
ansible.builtin.command:
9+
cmd: portsnap fetch --interactive
1010
creates: /var/db/portsnap/INDEX
1111

1212
- name: (FreeBSD) Extract ports
13-
ansible.builtin.command: portsnap extract
14-
args:
13+
ansible.builtin.command:
14+
cmd: portsnap extract
1515
creates: /usr/ports
1616

1717
- name: (FreeBSD) {{ nginx_setup | capitalize }} NGINX
18-
when: ansible_facts['system'] == "FreeBSD"
18+
when: ansible_facts['system'] == 'FreeBSD'
1919
block:
2020
- name: (FreeBSD) {{ nginx_setup | capitalize }} NGINX package
2121
community.general.pkgng:
@@ -33,7 +33,7 @@
3333
notify: (Handler) Run NGINX
3434

3535
- name: (OpenBSD) {{ nginx_setup | capitalize }} NGINX
36-
when: ansible_facts['system'] == "OpenBSD"
36+
when: ansible_facts['system'] == 'OpenBSD'
3737
block:
3838
- name: (OpenBSD) {{ nginx_setup | capitalize }} NGINX package
3939
community.general.openbsd_pkg:
@@ -52,7 +52,7 @@
5252
notify: (Handler) Run NGINX
5353

5454
- name: (NetBSD) {{ nginx_setup | capitalize }} NGINX
55-
when: ansible_facts['system'] == "NetBSD"
55+
when: ansible_facts['system'] == 'NetBSD'
5656
block:
5757
- name: (NetBSD) {{ nginx_setup | capitalize }} NGINX package
5858
ansible.builtin.command: pkg_add www/nginx{{ nginx_version | default('') }}

tasks/opensource/install-debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
name: nginx{{ nginx_version | default('') }}
2828
state: "{{ nginx_state }}"
2929
update_cache: true
30-
allow_downgrade: "{{ omit if ansible_version.full is version('2.12', '<') else true }}"
30+
allow_downgrade: "{{ omit if ansible_version['full'] is version('2.12', '<') else true }}"
3131
ignore_errors: "{{ ansible_check_mode }}"
3232
notify: (Handler) Run NGINX

tasks/opensource/install-distribution.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: (CentOS/RHEL 7) Set up the EPEL repository
33
when:
4-
- ansible_facts['distribution'] in ["CentOS", "RedHat"]
4+
- ansible_facts['distribution'] in ['CentOS', 'RedHat']
55
- ansible_facts['distribution_major_version'] is version('7', '==')
66
- nginx_install_epel_release | bool
77
block:
@@ -18,7 +18,7 @@
1818
ansible.builtin.yum:
1919
name: oracle-epel-release-el7
2020
when:
21-
- ansible_facts['distribution'] == "OracleLinux"
21+
- ansible_facts['distribution'] == 'OracleLinux'
2222
- ansible_facts['distribution_major_version'] is version('7', '==')
2323
- nginx_install_epel_release | bool
2424

@@ -28,14 +28,14 @@
2828
state: absent
2929
line: tsflags=nodocs
3030
when:
31-
- ansible_facts['distribution'] == "CentOS"
31+
- ansible_facts['distribution'] == 'CentOS'
3232
- ansible_facts['distribution_major_version'] is version('7', '==')
3333

3434
- name: (Amazon Linux) Enable the NGINX Amazon extras package repository
35-
ansible.builtin.command: amazon-linux-extras enable nginx1
36-
args:
35+
ansible.builtin.command:
36+
cmd: amazon-linux-extras enable nginx1
3737
creates: /usr/sbin/nginx
38-
when: ansible_facts['distribution'] == "Amazon"
38+
when: ansible_facts['distribution'] == 'Amazon'
3939

4040
- name: "{{ nginx_setup | capitalize }} NGINX from the distribution's package repository"
4141
ansible.builtin.package:

0 commit comments

Comments
 (0)