Skip to content

Commit daab4d0

Browse files
authored
Refactor how supported distributions are checked (#233)
1 parent 9b8787e commit daab4d0

File tree

3 files changed

+39
-47
lines changed

3 files changed

+39
-47
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.8.2 (Unreleased)
44

5+
FEATURES:
6+
7+
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.
8+
59
ENHANCEMENTS:
610

711
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`.
Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,32 @@
11
---
2-
- name: (WAF) Set supported_os_waf when platform and major/minor version are in the WAF supported platforms dictionary
3-
when: nginx_app_protect_waf_enable | bool and nginx_app_protect_waf_state != "absent"
4-
block:
5-
- name: (WAF) Set fact to true if item present in dictionary
6-
ansible.builtin.set_fact:
7-
supported_os_waf: true
8-
when:
9-
- ansible_distribution | lower in item.key
10-
- ansible_distribution_version | regex_search('\\d+\\.?\\d*') in item.value
11-
loop: "{{ query('dict', nginx_app_protect_waf_linux_families) }}"
12-
13-
- name: (WAF) Set supported_os_waf to false if fact not defined
14-
ansible.builtin.set_fact:
15-
supported_os_waf: false
16-
when: supported_os_waf is not defined
17-
18-
- name: (WAF) Abort if the OS / version combination is not supported
19-
ansible.builtin.fail:
20-
msg: NGINX App Protect WAF is not supported on OS family {{ ansible_distribution }} version {{ ansible_distribution_version }}
21-
when: not supported_os_waf
22-
23-
- name: (DoS) Set supported_os_dos when platform and major/minor version are in the DoS supported platforms dictionary
24-
when: nginx_app_protect_dos_enable | bool and nginx_app_protect_dos_state != "absent"
25-
block:
26-
- name: (DoS) Set fact to true if item present in dictionary
27-
ansible.builtin.set_fact:
28-
supported_os_dos: true
29-
when:
30-
- ansible_distribution | lower in item.key
31-
- ansible_distribution_version | regex_search('\\d+\\.?\\d+') in item.value
32-
loop: "{{ query('dict', nginx_app_protect_dos_linux_families) }}"
33-
34-
- name: (DoS) Set supported_os_dos to false if fact not defined
35-
ansible.builtin.set_fact:
36-
supported_os_dos: false
37-
when: supported_os_dos is not defined
2+
- name: (WAF) Check whether you are using a supported NGINX App Protect WAF distribution
3+
ansible.builtin.assert:
4+
that:
5+
- ansible_distribution | lower in nginx_app_protect_waf_linux_families.keys() | list
6+
- ansible_distribution_version | regex_search('\\d+\\.?\\d*') in nginx_app_protect_waf_linux_families[ansible_distribution | lower]
7+
success_msg: Your distribution, {{ ansible_distribution }} {{ ansible_distribution_version }}, is supported by NGINX App Protect WAF
8+
fail_msg: Your distribution, {{ ansible_distribution }} {{ ansible_distribution_version }}, is not supported by NGINX App Protect WAF
9+
when:
10+
- nginx_app_protect_waf_enable | bool
11+
- nginx_app_protect_waf_state != "absent"
12+
ignore_errors: true # noqa ignore-errors
3813

39-
- name: (DoS) Abort if the OS / version combination is not supported
40-
ansible.builtin.fail:
41-
msg: NGINX App Protect DoS is not supported on OS family {{ ansible_distribution }} version {{ ansible_distribution_version }}
42-
when: not supported_os_dos
14+
- name: (DoS) Check whether you are using a supported NGINX App Protect DoS distribution
15+
ansible.builtin.assert:
16+
that:
17+
- ansible_distribution | lower in nginx_app_protect_dos_linux_families.keys() | list
18+
- ansible_distribution_version | regex_search('\\d+\\.?\\d*') in nginx_app_protect_dos_linux_families[ansible_distribution | lower]
19+
success_msg: Your distribution, {{ ansible_distribution }} {{ ansible_distribution_version }}, is supported by NGINX App Protect DoS
20+
fail_msg: Your distribution, {{ ansible_distribution }} {{ ansible_distribution_version }}, is not supported by NGINX App Protect DoS
21+
when:
22+
- nginx_app_protect_dos_enable | bool
23+
- nginx_app_protect_dos_state != "absent"
24+
ignore_errors: true # noqa ignore-errors
4325

44-
- name: Abort if installing on RHEL > 7 without subscription details
26+
- name: Abort if installing NGINX App Protect on RHEL >7 without subscription details
4527
ansible.builtin.fail:
46-
msg: NGINX App Protect cannot be installed on OS family {{ ansible_distribution }} version {{ ansible_distribution_version }} without setting the 'nginx_app_protect_use_rhel_subscription_repos'
47-
variable
28+
msg: NGINX App Protect cannot be installed on {{ ansible_distribution }} {{ ansible_distribution_version }} without setting the 'nginx_app_protect_use_rhel_subscription_repos' variable
4829
when:
4930
- ansible_distribution == "RedHat"
50-
- ansible_distribution_version | int > 7
31+
- ansible_distribution_major_version is version('7', '>')
5132
- not nginx_app_protect_use_rhel_subscription_repos | bool

tasks/main.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
---
2-
- name: Check if OS is supported for NGINX App Protect WAF or DoS install
2+
- name: Check whether you are using a supported NGINX App Protect distribution
33
ansible.builtin.include_tasks: "{{ role_path }}/tasks/common/prerequisites/validate-supported-os.yml"
44
when: nginx_app_protect_waf_state != "absent"
55
or nginx_app_protect_dos_state != "absent"
6+
tags: nginx_app_protect_check_support
67

7-
- name: Fail if variables for 'nginx_app_protect_security_policy_file_enable' are not defined
8+
- name: Check if the variables for 'nginx_app_protect_security_policy_file_enable' are defined
89
ansible.builtin.assert:
910
that:
1011
- "{{ item }} is defined"
1112
- "{{ item }} | length > 0"
13+
fail_msg: If you want to publish a security policy file, don't forget to define at least one 'src' and 'dest' variables
1214
loop:
1315
- nginx_app_protect_security_policy_file.0.src
1416
- nginx_app_protect_security_policy_file.0.dest
1517
when: nginx_app_protect_security_policy_file_enable | bool
18+
ignore_errors: true # noqa ignore-errors
19+
tags: nginx_app_protect_check_policy_file
1620

17-
- name: Fail if variables for 'nginx_app_protect_log_policy_file_enable' are not defined
21+
- name: Check if the variables for 'nginx_app_protect_log_policy_file_enable' are defined
1822
ansible.builtin.assert:
1923
that:
2024
- "{{ item }} is defined"
2125
- "{{ item }} | length > 0"
26+
fail_msg: If you want to publish a log policy file, don't forget to define at least one 'src' and 'dest' variables
2227
loop:
2328
- nginx_app_protect_log_policy_file.0.src
2429
- nginx_app_protect_log_policy_file.0.dest
2530
when: nginx_app_protect_log_policy_file_enable | bool
31+
ignore_errors: true # noqa ignore-errors
32+
tags: nginx_app_protect_check_policy_file
2633

2734
- name: Install prerequisites
2835
ansible.builtin.include_tasks: "{{ role_path }}/tasks/common/prerequisites/prerequisites.yml"

0 commit comments

Comments
 (0)