Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize code from dot to array notation #584

Merged
merged 18 commits into from
Jan 29, 2023
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 0.23.3 (Unreleased)
## 0.24.0 (Unreleased)

BREAKING CHANGES:

Expand All @@ -27,6 +27,8 @@ FEATURES:

ENHANCEMENTS:

* Standardize code from dot to array notation to keep in with the standards set by the other roles in the Ansible NGINX core collection.
* Bump the minimum version of Ansible core required to run the role to `2.12` (`2.11` is no longer supported by Ansible).
* Improve validation of supported distributions when installing NGINX from the official repository.
* 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`.
* Use the official GitHub repositories as the source for the various packages required to compile NGINX OSS from source.
Expand Down
14 changes: 7 additions & 7 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
enabled: true
when:
- nginx_start | bool
- nginx_state != "absent"
- nginx_state != 'absent'
- not ansible_check_mode | bool
listen: (Handler) Run NGINX

Expand All @@ -22,18 +22,18 @@
ignore_errors: true
check_mode: false
changed_when: false
when: nginx_state != "absent"
when: nginx_state != 'absent'
listen: (Handler) Run NGINX

- name: (Handler) Print NGINX error if syntax check fails
ansible.builtin.debug:
var: config_check.stderr_lines
failed_when: config_check.rc != 0
failed_when: config_check['rc'] != 0
when:
- config_check.stderr_lines is defined
- config_check.stderr_lines != []
- config_check.rc != 0
- nginx_state != "absent"
- config_check['stderr_lines'] is defined
- config_check['stderr_lines'] != []
- config_check['rc'] != 0
- nginx_state != 'absent'
listen: (Handler) Run NGINX

- name: (Handler) Start NGINX Amplify agent
Expand Down
31 changes: 9 additions & 22 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
---
galaxy_info:
author: nginxinc
description: Official Ansible role for NGINX
description: Official Ansible role for installing NGINX
role_name: nginx
company: F5, Inc.

license: Apache License, Version 2.0

min_ansible_version: "2.12"
min_ansible_version: '2.12'

platforms:
- name: Alpine
versions:
- all
versions: [all]
- name: Amazon Linux 2
versions:
- all
versions: [all]
- name: Debian
versions:
- bullseye
versions: [bullseye]
- name: EL
versions:
- "7"
- "8"
- "9"
versions: ['7', '8', '9']
- name: FreeBSD
versions:
- "12.1"
versions: ['12.1']
- name: Ubuntu
versions:
- bionic
- focal
- impish
- jammy
versions: [bionic, focal, impish, jammy]
- name: SLES
versions:
- "12"
- "15"
versions: ['12', '15']

galaxy_tags:
- nginx
Expand Down
1 change: 0 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
name: ansible-role-nginx
vars:
nginx_modules:
- brotli
- geoip
- image-filter
- njs
Expand Down
2 changes: 1 addition & 1 deletion tasks/amplify/setup-redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: (Amazon Linux/CentOS/RHEL) Add NGINX Amplify agent repository
ansible.builtin.yum_repository:
name: nginx-amplify
baseurl: https://packages.amplify.nginx.com/{{ (ansible_facts['distribution_major_version'] == "7") | ternary('', 'py3/') }}{{ (ansible_facts['distribution'] == "Amazon") | ternary('amzn', 'centos') }}/$releasever/$basearch/
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/
description: NGINX Amplify Agent
enabled: true
gpgcheck: true
Expand Down
8 changes: 4 additions & 4 deletions tasks/config/setup-logrotate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
- name: (Alpine Linux) Install logrotate
community.general.apk:
name: logrotate
when: ansible_facts['os_family'] == "Alpine"
when: ansible_facts['os_family'] == 'Alpine'

- name: (Debian/Ubuntu) Install logrotate
ansible.builtin.apt:
name: logrotate
state: present
when: ansible_facts['os_family'] == "Debian"
when: ansible_facts['os_family'] == 'Debian'

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

- name: (SLES) Install Logrotate
community.general.zypper:
name: logrotate
state: present
when: ansible_facts['os_family'] == "Suse"
when: ansible_facts['os_family'] == 'Suse'

- name: Create logrotate config
ansible.builtin.template:
Expand Down
6 changes: 3 additions & 3 deletions tasks/keys/setup-keys.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: (Alpine Linux) Set up signing key
when: ansible_facts['os_family'] == "Alpine"
when: ansible_facts['os_family'] == 'Alpine'
block:
- name: (Alpine Linux) Set up NGINX signing key URL
ansible.builtin.set_fact:
Expand All @@ -15,14 +15,14 @@
- name: (Debian/Red Hat/SLES OSs) Set up NGINX signing key URL
ansible.builtin.set_fact:
keysite: "{{ nginx_signing_key | default(nginx_default_signing_key_pgp) }}"
when: ansible_facts['os_family'] != "Alpine"
when: ansible_facts['os_family'] != 'Alpine'

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

- name: (Red Hat/SLES OSs) Add NGINX signing key
ansible.builtin.rpm_key:
Expand Down
18 changes: 9 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

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

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

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

- name: Set up NGINX Plus license
ansible.builtin.include_tasks: "{{ role_path }}/tasks/plus/setup-license.yml"
when:
- nginx_type == "plus"
- nginx_type == 'plus'
- nginx_setup_license | bool
tags: nginx_setup_license

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

- name: "{{ nginx_setup | capitalize }} NGINX dynamic modules"
Expand All @@ -45,14 +45,14 @@
- name: Remove NGINX Plus license
ansible.builtin.include_tasks: "{{ role_path }}/tasks/plus/remove-license.yml"
when:
- nginx_type == "plus"
- nginx_type == 'plus'
- nginx_remove_license | bool
tags: nginx_remove_license

- name: Modify systemd parameters
ansible.builtin.include_tasks: "{{ role_path }}/tasks/config/modify-systemd.yml"
when:
- ansible_facts['service_mgr'] == "systemd"
- ansible_facts['service_mgr'] == 'systemd'
- nginx_service_modify | bool
tags: nginx_modify_systemd

Expand All @@ -64,14 +64,14 @@
when:
- nginx_enable | bool
- nginx_debug_output | bool
- nginx_state != "absent"
- nginx_state != 'absent'
tags: nginx_debug_output

- name: Configure logrotate for NGINX
ansible.builtin.include_tasks: "{{ role_path }}/tasks/config/setup-logrotate.yml"
when:
- nginx_logrotate_conf_enable | bool
- nginx_state != "absent"
- nginx_state != 'absent'
tags: nginx_logrotate_config

- name: Install NGINX Amplify
Expand Down
40 changes: 20 additions & 20 deletions tasks/modules/install-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
- name: (Amazon Linux/RHEL 7) Install libmaxminddb
ansible.builtin.yum:
name: https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/libmaxminddb-1.2.0-6.el7.x86_64.rpm
when: '"libmaxminddb" not in packages.results'
when: "'libmaxminddb' not in packages['results']"

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

- name: Install NGINX modules
ansible.builtin.package:
name: "nginx-{{ (nginx_type == 'plus') | ternary('plus-', '') }}module-{{ item.name | default(item) }}\
{{ (nginx_repository is not defined and ansible_facts['os_family'] == 'Alpine' and nginx_type != 'plus') | ternary('@nginx', '') }}{{ item.version | default('') }}"
state: "{{ item.state | default('present') }}"
name: "nginx-{{ (nginx_type == 'plus') | ternary('plus-', '') }}module-{{ item['name'] | default(item) }}\
{{ (nginx_repository is not defined and ansible_facts['os_family'] == 'Alpine' and nginx_type != 'plus') | ternary('@nginx', '') }}{{ item['version'] | default('') }}"
state: "{{ item['state'] | default('present') }}"
loop: "{{ nginx_modules }}"
when:
- (item.name | default(item) in nginx_modules_list and nginx_type == 'opensource')
or (item.name | default(item) in nginx_plus_modules_list and nginx_type == 'plus')
- not (item.name | default(item) == "brotli")
or not (ansible_facts['os_family'] == "Suse" and ansible_facts['distribution_major_version'] is version('12', '=='))
- not (item.name | default(item) == "geoip")
or not ((ansible_facts['os_family'] == "FreeBSD")
or (ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('8', '>=')))
- not (item.name | default(item) == "geoip2")
or not (ansible_facts['os_family'] == "Suse")
- not (item.name | default(item) == "lua")
or not (ansible_facts['architecture'] == "s390x")
- not (item.name | default(item) == "opentracing")
or not (ansible_facts['os_family'] == "Suse" and ansible_facts['distribution_major_version'] is version('12', '=='))
- (item['name'] | default(item) in nginx_modules_list and nginx_type == 'opensource')
or (item['name'] | default(item) in nginx_plus_modules_list and nginx_type == 'plus')
- not (item['name'] | default(item) == 'brotli')
or not (ansible_facts['os_family'] == 'Suse' and ansible_facts['distribution_major_version'] is version('12', '=='))
- not (item['name'] | default(item) == "geoip")
or not ((ansible_facts['os_family'] == 'FreeBSD')
or (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('8', '>=')))
- not (item['name'] | default(item) == 'geoip2')
or not (ansible_facts['os_family'] == 'Suse')
- not (item['name'] | default(item) == 'lua')
or not (ansible_facts['architecture'] == 's390x')
- not (item['name'] | default(item) == 'opentracing')
or not (ansible_facts['os_family'] == 'Suse' and ansible_facts['distribution_major_version'] is version('12', '=='))
16 changes: 8 additions & 8 deletions tasks/opensource/install-bsd.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
- name: (FreeBSD) Update ports
when:
- ansible_facts['system'] == "FreeBSD"
- ansible_facts['system'] == 'FreeBSD'
- nginx_bsd_update_ports | bool
block:
- name: (FreeBSD) Fetch ports
ansible.builtin.command: portsnap fetch --interactive
args:
ansible.builtin.command:
cmd: portsnap fetch --interactive
creates: /var/db/portsnap/INDEX

- name: (FreeBSD) Extract ports
ansible.builtin.command: portsnap extract
args:
ansible.builtin.command:
cmd: portsnap extract
creates: /usr/ports

- name: (FreeBSD) {{ nginx_setup | capitalize }} NGINX
when: ansible_facts['system'] == "FreeBSD"
when: ansible_facts['system'] == 'FreeBSD'
block:
- name: (FreeBSD) {{ nginx_setup | capitalize }} NGINX package
community.general.pkgng:
Expand All @@ -33,7 +33,7 @@
notify: (Handler) Run NGINX

- name: (OpenBSD) {{ nginx_setup | capitalize }} NGINX
when: ansible_facts['system'] == "OpenBSD"
when: ansible_facts['system'] == 'OpenBSD'
block:
- name: (OpenBSD) {{ nginx_setup | capitalize }} NGINX package
community.general.openbsd_pkg:
Expand All @@ -52,7 +52,7 @@
notify: (Handler) Run NGINX

- name: (NetBSD) {{ nginx_setup | capitalize }} NGINX
when: ansible_facts['system'] == "NetBSD"
when: ansible_facts['system'] == 'NetBSD'
block:
- name: (NetBSD) {{ nginx_setup | capitalize }} NGINX package
ansible.builtin.command: pkg_add www/nginx{{ nginx_version | default('') }}
Expand Down
2 changes: 1 addition & 1 deletion tasks/opensource/install-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
name: nginx{{ nginx_version | default('') }}
state: "{{ nginx_state }}"
update_cache: true
allow_downgrade: "{{ omit if ansible_version.full is version('2.12', '<') else true }}"
allow_downgrade: "{{ omit if ansible_version['full'] is version('2.12', '<') else true }}"
ignore_errors: "{{ ansible_check_mode }}"
notify: (Handler) Run NGINX
12 changes: 6 additions & 6 deletions tasks/opensource/install-distribution.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: (CentOS/RHEL 7) Set up the EPEL repository
when:
- ansible_facts['distribution'] in ["CentOS", "RedHat"]
- ansible_facts['distribution'] in ['CentOS', 'RedHat']
- ansible_facts['distribution_major_version'] is version('7', '==')
- nginx_install_epel_release | bool
block:
Expand All @@ -18,7 +18,7 @@
ansible.builtin.yum:
name: oracle-epel-release-el7
when:
- ansible_facts['distribution'] == "OracleLinux"
- ansible_facts['distribution'] == 'OracleLinux'
- ansible_facts['distribution_major_version'] is version('7', '==')
- nginx_install_epel_release | bool

Expand All @@ -28,14 +28,14 @@
state: absent
line: tsflags=nodocs
when:
- ansible_facts['distribution'] == "CentOS"
- ansible_facts['distribution'] == 'CentOS'
- ansible_facts['distribution_major_version'] is version('7', '==')

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

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