Skip to content

Commit 3e4f941

Browse files
authored
Refactor Ansible facts from dot to array notation (#237)
1 parent 016fbe9 commit 3e4f941

File tree

17 files changed

+67
-66
lines changed

17 files changed

+67
-66
lines changed

CHANGELOG.md

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

77
* Validate that various role variables have been set to one of the allowed values.
88
* Refactor how this role checks if your distribution is supported NGINX App Protect. The role will no longer fail if the target distribution is not supported, instead, you will get a warning. This should help with the occasional lag between new releases of distributions and/or NGINX App Protect and this role being updated to support those releases. In addition, the role will also now check if your distribution's architecture is supported.
9+
* Refactor Ansible facts from dot to array notation to keep in with the standards set by the other roles in the Ansible NGINX core collection.
910
* Add support for Debian bullseye for NGINX App Protect WAF.
1011
* Add support for Oracle Linux 7.x & 8.x for NGINX App Protect WAF.
1112
* Add support for RHEL 8.7.

molecule/common/cleanup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- name: (RHEL) Unregister system from RHEL subscription manager
2727
community.general.redhat_subscription:
2828
state: absent
29-
when: ansible_distribution == "RedHat"
29+
when: ansible_facts['distribution'] == "RedHat"
3030
rescue:
3131
- name: It's ok we're at startup
3232
ansible.builtin.meta: noop

molecule/default/converge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
username: "{{ lookup('env', 'RHEL_USERNAME') }}"
1717
password: "{{ lookup('env', 'RHEL_PASSWORD') }}"
1818
when:
19-
- ansible_distribution == "RedHat"
19+
- ansible_facts['distribution'] == "RedHat"
2020
- rhel_subscription | bool
2121
tasks:
2222
- name: Install NGINX App Protect WAF

molecule/dos/converge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
username: "{{ lookup('env', 'RHEL_USERNAME') }}"
1717
password: "{{ lookup('env', 'RHEL_PASSWORD') }}"
1818
when:
19-
- ansible_distribution == "RedHat"
19+
- ansible_facts['distribution'] == "RedHat"
2020
- rhel_subscription| bool
2121
tasks:
2222
- name: Install NGINX App Protect DoS

molecule/specific-version/converge.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
tasks:
1414
- name: Set NGINX App Protect WAF signature version fact
1515
ansible.builtin.set_fact:
16-
nginx_app_protect_waf_signatures_version: "{{ app_protect_signature_version_matrix[ansible_os_family | lower] }}{{ (ansible_os_family | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '') }}"
16+
nginx_app_protect_waf_signatures_version: "{{ app_protect_signature_version_matrix[ansible_facts['os_family'] | lower] }}{{ (ansible_facts['os_family'] | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '') }}"
1717
when: specify_app_protect_signatures_version | bool
1818

1919
- name: Set NGINX App Protect WAF threat campaigns version fact
2020
ansible.builtin.set_fact:
21-
nginx_app_protect_waf_threat_campaigns_version: "{{ app_protect_threat_campaigns_version_matrix[ansible_os_family | lower] }}{{ (ansible_os_family | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '') }}"
21+
nginx_app_protect_waf_threat_campaigns_version: "{{ app_protect_threat_campaigns_version_matrix[ansible_facts['os_family'] | lower] }}{{ (ansible_facts['os_family'] | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '') }}"
2222
when: specify_app_protect_threat_campaigns_version | bool
2323

2424
- name: Install NGINX App Protect WAF

molecule/specific-version/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161
- name: Verify installed NAP signatures version matches requested version # noqa jinja[spacing]
6262
ansible.builtin.assert:
63-
that: "{{ (ansible_facts.packages['app-protect-attack-signatures'] | map(attribute='version') | first) == (app_protect_signature_version_matrix[ansible_os_family | lower] | regex_replace('^-|=','') + (ansible_os_family | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '')) }}"
63+
that: "{{ (ansible_facts['packages']['app-protect-attack-signatures'] | map(attribute='version') | first) == (app_protect_signature_version_matrix[ansible_facts['os_family'] | lower] | regex_replace('^-|=','') + (ansible_facts['os_family'] | lower == 'debian') | ternary('~' ~ ansible_facts['distribution_release'], '')) }}"
6464

6565
- name: Verify installed NAP threat campaigns version matches requested version # noqa jinja[spacing]
6666
ansible.builtin.assert:
67-
that: "{{ (ansible_facts.packages['app-protect-threat-campaigns'] | map(attribute='version') | first) == (app_protect_threat_campaigns_version_matrix[ansible_os_family | lower] | regex_replace('^-|=','') + (ansible_os_family | lower == 'debian') | ternary('~' ~ ansible_distribution_release, '')) }}"
67+
that: "{{ (ansible_facts['packages']['app-protect-threat-campaigns'] | map(attribute='version') | first) == (app_protect_threat_campaigns_version_matrix[ansible_facts['os_family'] | lower] | regex_replace('^-|=','') + (ansible_facts['os_family'] | lower == 'debian') | ternary('~' ~ ansible_facts['distribution_release'], '')) }}"

molecule/uninstall/prepare.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
username: "{{ lookup('env', 'RHEL_USERNAME') }}"
3535
password: "{{ lookup('env', 'RHEL_PASSWORD') }}"
3636
when:
37-
- ansible_distribution == "RedHat"
37+
- ansible_facts['distribution'] == "RedHat"
3838
- rhel_subscription| bool
3939
tasks:
4040
- name: Install NGINX App Protect WAF
@@ -54,5 +54,5 @@
5454
community.general.redhat_subscription:
5555
state: absent
5656
when:
57-
- ansible_distribution == "RedHat"
57+
- ansible_facts['distribution'] == "RedHat"
5858
- rhel_subscription | bool

tasks/common/config/configure-app-protect.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
block:
55
- name: Ensure NGINX App Protect security policy directories exist
66
ansible.builtin.file:
7-
path: "{{ item.dest | default('/etc/app_protect/conf') | dirname }}"
7+
path: "{{ item['dest'] | default('/etc/app_protect/conf') | dirname }}"
88
state: directory
99
mode: 0755
1010
loop: "{{ nginx_app_protect_security_policy_file }}"
1111

1212
- name: Copy NGINX App Protect security policy files
1313
ansible.builtin.copy:
14-
src: "{{ item.src }}"
15-
dest: "{{ item.dest | default('/etc/app_protect/conf') }}"
14+
src: "{{ item['src'] }}"
15+
dest: "{{ item['dest'] | default('/etc/app_protect/conf') }}"
1616
backup: true
1717
mode: 0644
1818
loop: "{{ nginx_app_protect_security_policy_file }}"
@@ -22,15 +22,15 @@
2222
block:
2323
- name: Ensure NGINX App Protect log policy directories exist
2424
ansible.builtin.file:
25-
path: "{{ item.dest | default('/etc/app_protect/conf') | dirname }}"
25+
path: "{{ item['dest'] | default('/etc/app_protect/conf') | dirname }}"
2626
state: directory
2727
mode: 0755
2828
loop: "{{ nginx_app_protect_log_policy_file }}"
2929

3030
- name: Copy NGINX App Protect log policy files
3131
ansible.builtin.copy:
32-
src: "{{ item.src }}"
33-
dest: "{{ item.dest | default('/etc/app_protect/conf') }}"
32+
src: "{{ item['src'] }}"
33+
dest: "{{ item['dest'] | default('/etc/app_protect/conf') }}"
3434
backup: true
3535
mode: 0644
3636
loop: "{{ nginx_app_protect_log_policy_file }}"

tasks/common/install/remove-license.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
nginx_app_protect_license_status: absent
55

66
- name: Delete NGINX App Protect WAF repository data
7-
ansible.builtin.include_tasks: "{{ role_path }}/tasks/waf/install-{{ ansible_os_family | lower }}.yml"
7+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/waf/install-{{ ansible_facts['os_family'] | lower }}.yml"
88
when: nginx_app_protect_waf_enable | bool
99

1010
- name: Delete NGINX App Protect DoS repository data
11-
ansible.builtin.include_tasks: "{{ role_path }}/tasks/dos/install-{{ ansible_os_family | lower }}.yml"
11+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/dos/install-{{ ansible_facts['os_family'] | lower }}.yml"
1212
when: nginx_app_protect_dos_enable | bool
1313

1414
- name: Delete NGINX App Protect license

tasks/common/install/setup-license.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: (Alpine Linux) Set up NGINX App Protect WAF/DoS license
3-
when: ansible_os_family == "Alpine"
3+
when: ansible_facts['os_family'] == "Alpine"
44
block:
55
- name: Install cryptography package
66
ansible.builtin.package:
@@ -14,14 +14,14 @@
1414

1515
- name: (Alpine Linux) Copy NGINX App Protect WAF/DoS certificate
1616
ansible.builtin.copy:
17-
src: "{{ nginx_app_protect_license.certificate }}"
17+
src: "{{ nginx_app_protect_license['certificate'] }}"
1818
dest: /etc/apk/cert.pem
1919
decrypt: true
2020
mode: 0444
2121

2222
- name: (Alpine Linux) Copy NGINX App Protect WAF/DoS key
2323
ansible.builtin.copy:
24-
src: "{{ nginx_app_protect_license.key }}"
24+
src: "{{ nginx_app_protect_license['key'] }}"
2525
dest: /etc/apk/cert.key
2626
decrypt: true
2727
mode: 0444
@@ -45,7 +45,7 @@
4545
fail_msg: Something went wrong! Make sure your App Protect WAF/DoS license is valid!
4646

4747
- name: (Debian/Red Hat OSs) Set up NGINX App Protect WAF/DoS license
48-
when: ansible_os_family != "Alpine"
48+
when: ansible_facts['os_family'] != "Alpine"
4949
block:
5050
- name: (Debian/Red Hat OSs) Create SSL directory
5151
ansible.builtin.file:
@@ -60,12 +60,12 @@
6060
decrypt: true
6161
mode: 0444
6262
loop:
63-
- "{{ nginx_app_protect_license.certificate }}"
64-
- "{{ nginx_app_protect_license.key }}"
63+
- "{{ nginx_app_protect_license['certificate'] }}"
64+
- "{{ nginx_app_protect_license['key'] }}"
6565

6666
- name: (Debian/Red Hat OSs) Install cryptography package
6767
ansible.builtin.package:
68-
name: "{{ (ansible_python.version.major == 3) | ternary('python3-cryptography', 'python2-cryptography') }}"
68+
name: "{{ (ansible_python['version']['major'] == 3) | ternary('python3-cryptography', 'python2-cryptography') }}"
6969

7070
- name: (Debian/Red Hat OSs) Check that NGINX App Protect WAF/DoS certificate is valid
7171
community.crypto.x509_certificate_info:
@@ -80,7 +80,7 @@
8080
- name: (Debian/Red Hat OSs) Check that NGINX App Protect WAF/DoS license is valid
8181
ansible.builtin.assert:
8282
that:
83-
- cert.expired == false
84-
- cert.public_key == key.public_key
83+
- "{{ not cert['expired'] | bool }}"
84+
- "{{ cert['public_key'] == key['public_key'] }}"
8585
success_msg: Your NGINX App Protect WAF/DoS license is valid!
8686
fail_msg: Something went wrong! Make sure your NGINX App Protect WAF/DoS license is valid!

0 commit comments

Comments
 (0)