Skip to content

Commit 0a92790

Browse files
authored
Check NGINX Plus license is valid (#538)
1 parent 228c88a commit 0a92790

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

.github/workflows/requirements/requirements_ansible.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ collections:
44
version: 5.4.0
55
- name: ansible.posix
66
version: 1.4.0
7+
- name: community.crypto
8+
version: 2.5.0
79
- name: community.docker
810
version: 2.7.0

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
FEATURES:
66

7+
* Check NGINX Plus license is valid before trying to install NGINX Plus (this means the role now requires the `community.crypto` collection).
78
* Add Ubuntu jammy (22.04) to the NGINX list of tested and supported platforms.
89
* Add RHEL 9 to the NGINX list of tested and supported platforms.
910
* Add Alpine Linux 3.16 to the NGINX list of tested and supported platforms (and remove Alpine Linux 3.12).

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ If you wish to install NGINX Plus using this role, you will need to obtain an NG
2828
version: 5.4.0
2929
- name: ansible.posix
3030
version: 1.4.0
31-
- name: community.docker # Only required if you plan to use Molecule (see below)
31+
- name: community.crypto # Only required if you plan to install NGINX Plus
32+
version: 2.5.0
33+
- name: community.docker # Only required if you plan to use Molecule (see below)
3234
version: 2.7.0
3335
```
3436

meta/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ galaxy_info:
5151

5252
collections:
5353
- ansible.posix
54+
- community.crypto
5455
- community.general

tasks/plus/setup-license.yml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@
1717
- "{{ nginx_license['certificate'] }}"
1818
- "{{ nginx_license['key'] }}"
1919

20+
- name: (Debian/Red Hat/SLES OSs) Install cryptography package
21+
ansible.builtin.package:
22+
name: "{{ (ansible_python['version']['major'] == 3) | ternary('python3-cryptography', 'python2-cryptography') }}"
23+
24+
- name: (Debian/Red Hat/SLES OSs) Check that NGINX Plus certificate is valid
25+
community.crypto.x509_certificate_info:
26+
path: /etc/ssl/nginx/nginx-repo.crt
27+
register: cert
28+
29+
- name: (Debian/Red Hat/SLES OSs) Check that NGINX Plus key is valid
30+
community.crypto.openssl_privatekey_info:
31+
path: /etc/ssl/nginx/nginx-repo.key
32+
register: key
33+
34+
- name: (Debian/Red Hat/SLES OSs) Check that NGINX Plus license is valid
35+
ansible.builtin.assert:
36+
that:
37+
- cert.expired == false
38+
- cert.public_key == key.public_key
39+
success_msg: Your NGINX Plus license is valid!
40+
fail_msg: Something went wrong! Make sure your NGINX Plus license is valid!
41+
2042
- name: (SLES) Create NGINX Plus license bundle
2143
block:
2244
- name: (SLES) Check combined NGINX Plus license bundle exists
@@ -35,23 +57,45 @@
3557

3658
- name: (Alpine Linux) Set up NGINX Plus license
3759
block:
60+
- name: Install cryptography package
61+
ansible.builtin.package:
62+
name: py3-cryptography
63+
3864
- name: (Alpine Linux) Create APK directory
3965
ansible.builtin.file:
4066
path: /etc/apk
4167
state: directory
4268
mode: 0755
4369

44-
- name: (Alpine Linux) Copy NGINX Plus key
70+
- name: (Alpine Linux) Copy NGINX Plus certificate
4571
ansible.builtin.copy:
46-
src: "{{ nginx_license['key'] }}"
47-
dest: /etc/apk/cert.key
72+
src: "{{ nginx_license['certificate'] }}"
73+
dest: /etc/apk/cert.pem
4874
decrypt: true
4975
mode: 0444
5076

51-
- name: (Alpine Linux) Copy NGINX Plus certificate
77+
- name: (Alpine Linux) Copy NGINX Plus key
5278
ansible.builtin.copy:
53-
src: "{{ nginx_license['certificate'] }}"
54-
dest: /etc/apk/cert.pem
79+
src: "{{ nginx_license['key'] }}"
80+
dest: /etc/apk/cert.key
5581
decrypt: true
5682
mode: 0444
83+
84+
- name: (Alpine Linux) Check that NGINX Plus certificate is valid
85+
community.crypto.x509_certificate_info:
86+
path: /etc/apk/cert.pem
87+
register: cert
88+
89+
- name: (Alpine Linux) Check that NGINX Plus key is valid
90+
community.crypto.openssl_privatekey_info:
91+
path: /etc/apk/cert.key
92+
register: key
93+
94+
- name: (Alpine Linux) Check that NGINX Plus license is valid
95+
ansible.builtin.assert:
96+
that:
97+
- cert.expired == false
98+
- cert.public_key == key.public_key
99+
success_msg: Your NGINX Plus license is valid!
100+
fail_msg: Something went wrong! Make sure your NGINX Plus license is valid!
57101
when: ansible_facts['os_family'] == "Alpine"

0 commit comments

Comments
 (0)