Skip to content

Commit 3fb69de

Browse files
authored
Fix NGINX Plus license removal option (#340)
1 parent ab76f7a commit 3fb69de

File tree

10 files changed

+38
-38
lines changed

10 files changed

+38
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ ENHANCEMENTS:
77
* Add survey to README.
88
* Improve README structure and use tables where relevant.
99
* Update Ansible (now Ansible base) to `2.10.2`, Ansible (now Ansible Community Distribution) to `2.10.0`, and yamllint to `1.25.0`.
10+
* Optimize NGINX Plus install/remove tasks.
1011

1112
BUG FIXES:
1213

1314
* Prevent TravisCI from trying to build (and failing) NGINX Plus images on external PRs.
14-
* Fix naming for SELinux facts dict.
15+
* Fix naming for SELinux facts dictionary.
1516
* Role now runs correctly when using Ansible's check mode.
17+
* Removing the NGINX Plus license in RHEL based distros should no longer return a repository not found error.
18+
* Fix issue when removing NGINX Plus license on some distributions.
19+
* Fix Amazon Linux NGINX Plus install while at it.
1620

1721
## 0.17.2 (September 24, 2020)
1822

tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
tags: nginx_setup_license
3939

4040
- name: Install NGINX Plus
41-
include_tasks: "{{ role_path }}/tasks/plus/install-plus.yml"
41+
include_tasks: "{{ role_path }}/tasks/plus/install-{{ ansible_facts['os_family'] | lower }}.yml"
4242
when: nginx_type == "plus"
4343
tags: nginx_install_plus
4444

tasks/plus/install-alpine.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
- name: (Alpine Linux) Configure NGINX Plus repository
2+
- name: (Alpine Linux) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
33
lineinfile:
44
path: /etc/apk/repositories
55
insertafter: EOF
6-
line: "{{ repository }}"
6+
line: "{{ nginx_repository | default(nginx_plus_default_repository_alpine) }}"
77
state: "{{ nginx_license_status | default ('present') }}"
88

99
- name: (Alpine Linux) Install NGINX Plus
1010
apk:
1111
name: "nginx-plus{{ nginx_version | default('') }}"
12-
repository: "{{ repository }}"
12+
repository: "{{ nginx_repository | default(nginx_plus_default_repository_alpine) }}"
1313
state: "{{ nginx_state }}"
1414
ignore_errors: "{{ ansible_check_mode }}"
15+
when: nginx_license_status is not defined
1516
notify: (Handler) Run NGINX

tasks/plus/install-debian.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: (Debian/Ubuntu) Set up NGINX Plus license verification
2+
- name: (Debian/Ubuntu) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus license verification
33
blockinfile:
44
path: /etc/apt/apt.conf.d/90nginx
55
create: yes
@@ -11,10 +11,10 @@
1111
state: "{{ nginx_license_status | default ('present') }}"
1212
mode: 0444
1313

14-
- name: (Debian/Ubuntu) Configure NGINX Plus repository
14+
- name: (Debian/Ubuntu) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
1515
apt_repository:
1616
filename: nginx-plus
17-
repo: "{{ repository }}"
17+
repo: "{{ nginx_repository | default(nginx_plus_default_repository_debian) }}"
1818
update_cache: no
1919
state: "{{ nginx_license_status | default ('present') }}"
2020
mode: 0644
@@ -25,4 +25,5 @@
2525
state: "{{ nginx_state }}"
2626
update_cache: yes
2727
ignore_errors: "{{ ansible_check_mode }}"
28+
when: nginx_license_status is not defined
2829
notify: (Handler) Run NGINX

tasks/plus/install-freebsd.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: (FreeBSD) Set up NGINX Plus license verification
2+
- name: (FreeBSD) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus license verification
33
blockinfile:
44
path: /usr/local/etc/pkg.conf
55
block: |
@@ -8,13 +8,13 @@
88
SSL_CLIENT_KEY_FILE: "/etc/ssl/nginx/nginx-repo.key" }
99
state: "{{ nginx_license_status | default ('present') }}"
1010

11-
- name: (FreeBSD) Configure NGINX Plus repository
11+
- name: (FreeBSD) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
1212
blockinfile:
1313
path: /etc/pkg/nginx-plus.conf
1414
create: yes
1515
block: |
1616
nginx-plus: {
17-
URL: {{ repository }}
17+
URL: {{ nginx_repository | default(nginx_plus_default_repository_freebsd) }}
1818
ENABLED: yes
1919
MIRROR_TYPE: SRV
2020
}
@@ -25,4 +25,5 @@
2525
pkgng:
2626
name: "nginx-plus{{ nginx_version | default('') }}"
2727
state: "{{ nginx_state }}"
28+
when: nginx_license_status is not defined
2829
notify: (Handler) Run NGINX

tasks/plus/install-plus.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

tasks/plus/install-redhat.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
- name: (Amazon Linux/CentOS/Oracle Linux/RHEL) Configure NGINX Plus repository
2+
- name: (Amazon Linux/CentOS/Oracle Linux/RHEL) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
33
yum_repository:
44
name: nginx-plus
5-
baseurl: "{{ repository }}"
5+
baseurl: "{{ nginx_repository |
6+
default(lookup('vars', 'nginx_plus_default_repository_' + ((ansible_facts['distribution'] == 'Amazon') | ternary('amazon', 'redhat')))) }}"
67
description: NGINX Plus Repository
78
sslclientcert: /etc/ssl/nginx/nginx-repo.crt
89
sslclientkey: /etc/ssl/nginx/nginx-repo.key
@@ -15,8 +16,7 @@
1516
yum:
1617
name: "nginx-plus{{ nginx_version | default('') }}"
1718
state: "{{ nginx_state }}"
18-
disablerepo: "*"
19-
enablerepo: "nginx-plus"
2019
update_cache: yes
2120
ignore_errors: "{{ ansible_check_mode }}"
21+
when: nginx_license_status is not defined
2222
notify: (Handler) Run NGINX

tasks/plus/install-suse.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
src: /etc/ssl/nginx
55
dest: /etc/ssl/nginx/nginx-repo-bundle.crt
66
mode: 0444
7+
when: nginx_license_status is not defined
78

8-
- name: (SLES) Configure NGINX Plus repository
9+
- name: (SLES) {{ nginx_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
910
zypper_repository:
1011
name: nginx-plus
11-
repo: "{{ repository }}"
12+
repo: "{{ nginx_repository | default(nginx_plus_default_repository_sles) }}"
1213
state: "{{ nginx_license_status | default ('present') }}"
1314

1415
- name: (SLES) Install NGINX Plus
@@ -17,4 +18,5 @@
1718
state: "{{ nginx_state }}"
1819
update_cache: yes
1920
ignore_errors: "{{ ansible_check_mode }}"
21+
when: nginx_license_status is not defined
2022
notify: (Handler) Run NGINX

tasks/plus/remove-license.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: Set NGINX Plus license state
2+
- name: Set NGINX Plus license state to absent
33
set_fact:
44
nginx_license_status: absent
55

@@ -18,5 +18,5 @@
1818
- /etc/apk/cert.pem
1919
when: ansible_facts['distribution'] == "Alpine"
2020

21-
- name: Delete NGINX Plus repository data
22-
include_tasks: "{{ role_path }}/tasks/plus/install-plus.yml"
21+
- name: Remove NGINX Plus repository data
22+
include_tasks: "{{ role_path }}/tasks/plus/install-{{ ansible_facts['os_family'] | lower }}.yml"

vars/main.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ nginx_default_repository:
3333
| ternary('mainline/', '') }}sles/{{ ansible_facts['distribution_major_version'] }}"
3434

3535
# Default NGINX Plus repositories
36-
nginx_plus_default_repository:
37-
alpine: "https://plus-pkgs.nginx.com/alpine/v{{ ansible_facts['distribution_version'] | regex_search('^[0-9]+\\.[0-9]+') }}/main"
38-
amazon: "https://plus-pkgs.nginx.com/amzn{{ (ansible_facts['distribution_version'] is version('2', '==')) | ternary('2', '') }}/$releasever/$basearch"
39-
debian: "deb [arch=amd64] https://plus-pkgs.nginx.com/{{ ansible_facts['distribution'] | lower }} {{ ansible_facts['distribution_release'] }} nginx-plus"
40-
freebsd: "https://plus-pkgs.nginx.com/freebsd/${ABI}/latest"
41-
redhat: "https://plus-pkgs.nginx.com/{{ (ansible_facts['distribution'] == 'CentOS')
42-
| ternary('centos', 'rhel') }}/{{ (ansible_facts['distribution_version'] is version('7.4', '>=')
43-
and ansible_facts['distribution_version'] is version('8', '<')) | ternary('7.4', ansible_facts['distribution_major_version']) }}/$basearch/"
44-
suse: "https://plus-pkgs.nginx.com/sles/{{ ansible_facts['distribution_major_version'] }}\
45-
?ssl_clientcert=/etc/ssl/nginx/nginx-repo-bundle.crt&ssl_verify=host"
36+
nginx_plus_default_repository_alpine: "https://plus-pkgs.nginx.com/alpine/v{{ ansible_facts['distribution_version'] | regex_search('^[0-9]+\\.[0-9]+') }}/main"
37+
nginx_plus_default_repository_amazon: "https://plus-pkgs.nginx.com/amzn{{ (ansible_facts['distribution_major_version'] is version('2', '==')) | ternary('2', '') }}/$releasever/$basearch"
38+
nginx_plus_default_repository_debian: "deb [arch=amd64] https://plus-pkgs.nginx.com/{{ ansible_facts['distribution'] | lower }} {{ ansible_facts['distribution_release'] }} nginx-plus"
39+
nginx_plus_default_repository_freebsd: "https://plus-pkgs.nginx.com/freebsd/${ABI}/latest"
40+
nginx_plus_default_repository_redhat: "https://plus-pkgs.nginx.com/{{ (ansible_facts['distribution'] == 'CentOS')
41+
| ternary('centos', 'rhel') }}/{{ (ansible_facts['distribution_version'] is version('7.4', '>=')
42+
and ansible_facts['distribution_version'] is version('8', '<')) | ternary('7.4', ansible_facts['distribution_major_version']) }}/$basearch/"
43+
nginx_plus_default_repository_sles: "https://plus-pkgs.nginx.com/sles/{{ ansible_facts['distribution_major_version'] }}\
44+
?ssl_clientcert=/etc/ssl/nginx/nginx-repo-bundle.crt&ssl_verify=peer"
4645

4746
# Alpine dependencies
4847
nginx_alpine_dependencies: [

0 commit comments

Comments
 (0)