Skip to content

Commit 016fbe9

Browse files
authored
Check distribution and validate role variables (#236)
1 parent 8ba6ecf commit 016fbe9

File tree

5 files changed

+138
-120
lines changed

5 files changed

+138
-120
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
FEATURES:
66

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.
7+
* Validate that various role variables have been set to one of the allowed values.
8+
* 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.
89
* Add support for Debian bullseye for NGINX App Protect WAF.
910
* Add support for Oracle Linux 7.x & 8.x for NGINX App Protect WAF.
1011
* Add support for RHEL 8.7.

tasks/common/prerequisites/validate-supported-os.yml

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

tasks/common/validate/validate.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
- name: (WAF) Check whether you are using a supported NGINX App Protect WAF distribution
3+
ansible.builtin.assert:
4+
that:
5+
- "{{ ansible_facts['distribution'] | lower in nginx_app_protect_waf_distributions.keys() | list }}"
6+
- "{{ (ansible_facts['distribution_version'] | regex_search('\\d+\\.?\\d*') in nginx_app_protect_waf_distributions[ansible_facts['distribution'] | lower]['versions'] | string)
7+
if ansible_facts['distribution'] | lower in ['ubuntu'] else ansible_facts['distribution_major_version'] in nginx_app_protect_waf_distributions[ansible_facts['distribution'] | lower]['versions'] | string }}"
8+
- "{{ ansible_facts['architecture'] in nginx_app_protect_waf_distributions[ansible_facts['distribution'] | lower]['architectures'] }}"
9+
success_msg: Your distribution, {{ nginx_app_protect_waf_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is supported by NGINX App Protect WAF.
10+
fail_msg: Your distribution, {{ nginx_app_protect_waf_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is not supported by NGINX App Protect WAF.
11+
when:
12+
- nginx_app_protect_waf_enable | bool
13+
- nginx_app_protect_waf_state != "absent"
14+
ignore_errors: true # noqa ignore-errors
15+
16+
- name: (DoS) Check whether you are using a supported NGINX App Protect DoS distribution
17+
ansible.builtin.assert:
18+
that:
19+
- "{{ ansible_facts['distribution'] | lower in nginx_app_protect_dos_distributions.keys() | list }}"
20+
- "{{ (ansible_facts['distribution_version'] | regex_search('\\d+\\.?\\d*') in nginx_app_protect_dos_distributions[ansible_facts['distribution'] | lower]['versions'] | string)
21+
if ansible_facts['distribution'] | lower in ['alpine', 'ubuntu'] else ansible_facts['distribution_major_version'] in nginx_app_protect_dos_distributions[ansible_facts['distribution'] | lower]['versions'] | string }}"
22+
- "{{ ansible_facts['architecture'] in nginx_app_protect_dos_distributions[ansible_facts['distribution'] | lower]['architectures'] }}"
23+
success_msg: Your distribution, {{ nginx_app_protect_dos_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is supported by NGINX App Protect DoS.
24+
fail_msg: Your distribution, {{ nginx_app_protect_dos_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is not supported by NGINX App Protect DoS.
25+
when:
26+
- nginx_app_protect_dos_enable | bool
27+
- nginx_app_protect_dos_state != "absent"
28+
ignore_errors: true # noqa ignore-errors
29+
30+
- name: Warn if installing NGINX App Protect on RHEL >7 without subscription details
31+
ansible.builtin.fail:
32+
msg: NGINX App Protect cannot be installed on Red Hat Enterprise Linux {{ ansible_distribution_version }} without a valid Red Hat Enterprise Linux subscription. Subscribe your target environment before running the role and then set the 'nginx_app_protect_use_rhel_subscription_repos' variable to true.
33+
when:
34+
- ansible_distribution == "RedHat"
35+
- ansible_distribution_major_version is version('7', '>')
36+
- not nginx_app_protect_use_rhel_subscription_repos | bool
37+
ignore_errors: true # noqa ignore-errors
38+
39+
- name: Check that 'nginx_app_protect_waf_setup' is an allowed value
40+
ansible.builtin.assert:
41+
that: nginx_app_protect_waf_setup in nginx_app_protect_setup_vars
42+
fail_msg: The value you used for 'nginx_app_protect_waf_setup', {{ nginx_app_protect_waf_setup }}, is not allowed. The allowed values are [{{ nginx_app_protect_setup_vars | join(', ') }}].
43+
when: nginx_app_protect_waf_enable | bool
44+
ignore_errors: true # noqa ignore-errors
45+
46+
- name: Check that 'nginx_app_protect_dos_setup' is an allowed value
47+
ansible.builtin.assert:
48+
that: nginx_app_protect_dos_setup in nginx_app_protect_setup_vars
49+
fail_msg: The value you used for 'nginx_app_protect_dos_setup', {{ nginx_app_protect_waf_setup }}, is not allowed. The allowed values are [{{ nginx_app_protect_setup_vars | join(', ') }}].
50+
when: nginx_app_protect_dos_enable | bool
51+
ignore_errors: true # noqa ignore-errors
52+
53+
- name: Check that the variables for 'nginx_app_protect_security_policy_file_enable' are defined
54+
ansible.builtin.assert:
55+
that:
56+
- "{{ item }} is defined"
57+
- "{{ item }} | length > 0"
58+
fail_msg: If you want to publish a security policy file, don't forget to define at least one 'src' and 'dest' variables
59+
loop:
60+
- nginx_app_protect_security_policy_file.0.src
61+
- nginx_app_protect_security_policy_file.0.dest
62+
when: nginx_app_protect_security_policy_file_enable | bool
63+
ignore_errors: true # noqa ignore-errors
64+
65+
- name: Check that the variables for 'nginx_app_protect_log_policy_file_enable' are defined
66+
ansible.builtin.assert:
67+
that:
68+
- "{{ item }} is defined"
69+
- "{{ item }} | length > 0"
70+
fail_msg: If you want to publish a log policy file, don't forget to define at least one 'src' and 'dest' variables
71+
loop:
72+
- nginx_app_protect_log_policy_file.0.src
73+
- nginx_app_protect_log_policy_file.0.dest
74+
when: nginx_app_protect_log_policy_file_enable | bool
75+
ignore_errors: true # noqa ignore-errors

tasks/main.yml

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
---
2-
- name: Check whether you are using a supported NGINX App Protect distribution
3-
ansible.builtin.include_tasks: "{{ role_path }}/tasks/common/prerequisites/validate-supported-os.yml"
4-
when: nginx_app_protect_waf_state != "absent"
5-
or nginx_app_protect_dos_state != "absent"
6-
tags: nginx_app_protect_check_support
2+
- name: Validate distribution and role variables
3+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/common/validate/validate.yml"
4+
tags: nginx_app_protect_validate
75

8-
- name: Check if the variables for 'nginx_app_protect_security_policy_file_enable' are defined
9-
ansible.builtin.assert:
10-
that:
11-
- "{{ item }} is defined"
12-
- "{{ 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
14-
loop:
15-
- nginx_app_protect_security_policy_file.0.src
16-
- nginx_app_protect_security_policy_file.0.dest
17-
when: nginx_app_protect_security_policy_file_enable | bool
18-
ignore_errors: true # noqa ignore-errors
19-
tags: nginx_app_protect_check_policy_file
20-
21-
- name: Check if the variables for 'nginx_app_protect_log_policy_file_enable' are defined
22-
ansible.builtin.assert:
23-
that:
24-
- "{{ item }} is defined"
25-
- "{{ 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
27-
loop:
28-
- nginx_app_protect_log_policy_file.0.src
29-
- nginx_app_protect_log_policy_file.0.dest
30-
when: nginx_app_protect_log_policy_file_enable | bool
31-
ignore_errors: true # noqa ignore-errors
32-
tags: nginx_app_protect_check_policy_file
33-
34-
- name: Install prerequisites
6+
- name: Set up prerequisites
357
ansible.builtin.include_tasks: "{{ role_path }}/tasks/common/prerequisites/prerequisites.yml"
368
when: nginx_app_protect_waf_enable | bool
379
or nginx_app_protect_dos_enable | bool

vars/main.yml

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
11
---
2-
# NGINX App Protect WAF platform matrix. Populate this dictionary of lists with appropriate values from ansible_distribution and ansible_distribution_version facts
3-
nginx_app_protect_waf_linux_families:
4-
amazon: [
5-
"2",
6-
]
7-
centos: [
8-
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9",
9-
]
10-
debian: [
11-
"11",
12-
]
13-
oraclelinux: [
14-
"8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7",
15-
]
16-
redhat: [
17-
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7",
18-
]
19-
ubuntu: [
20-
"18.04", "20.04",
21-
]
22-
23-
# NGINX App Protect DoS platform matrix. Populate this dictionary of lists with appropriate values from ansible_distribution and ansible_distribution_version facts
24-
nginx_app_protect_dos_linux_families:
25-
alpine: [
26-
"3.15",
27-
]
28-
centos: [
29-
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9",
30-
]
31-
debian: [
32-
"11",
33-
]
34-
redhat: [
35-
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7",
36-
]
37-
ubuntu: [
38-
"18.04", "20.04",
39-
]
40-
41-
nginx_app_protect_setup_vars: [
42-
install, uninstall, upgrade,
43-
]
2+
# Set the values allowed for various variables
3+
nginx_app_protect_setup_vars: [install, uninstall, upgrade]
444

5+
# Determine the current value of 'nginx_app_protect_*_state'
456
nginx_app_protect_state_vals:
467
install: present
478
uninstall: absent
@@ -53,26 +14,67 @@ nginx_app_protect_waf_state: "{{ nginx_app_protect_state_vals[nginx_app_protect_
5314
nginx_app_protect_dos_default_setup: install
5415
nginx_app_protect_dos_state: "{{ nginx_app_protect_state_vals[nginx_app_protect_dos_setup] | default(nginx_app_protect_state_vals[nginx_app_protect_dos_default_setup]) }}"
5516

17+
# NGINX App Protect WAF platform matrix. Populate this dictionary of lists with appropriate values from ansible_distribution and ansible_distribution_version facts
18+
nginx_app_protect_waf_distributions:
19+
amazon:
20+
name: Amazon Linux
21+
versions: [2]
22+
architectures: [x86_64]
23+
centos:
24+
name: CentOS
25+
versions: [7]
26+
architectures: [x86_64]
27+
debian:
28+
name: Debian
29+
versions: [11]
30+
architectures: [x86_64]
31+
oraclelinux:
32+
name: Oracle Linux
33+
versions: [8]
34+
architectures: [x86_64]
35+
redhat:
36+
name: Red Hat Enterprise Linux
37+
versions: [7, 8]
38+
architectures: [x86_64]
39+
ubuntu:
40+
name: Ubuntu
41+
versions: [18.04, 20.04]
42+
architectures: [x86_64]
43+
44+
# NGINX App Protect DoS platform matrix. Populate this dictionary of lists with appropriate values from ansible_distribution and ansible_distribution_version facts
45+
nginx_app_protect_dos_distributions:
46+
alpine:
47+
name: Alpine Linux
48+
versions: [3.15]
49+
architectures: [x86_64]
50+
centos:
51+
name: CentOS
52+
versions: [7]
53+
architectures: [x86_64]
54+
debian:
55+
name: Debian
56+
versions: [11]
57+
architectures: [x86_64]
58+
redhat:
59+
name: Red Hat Enterprise Linux
60+
versions: [7, 8]
61+
architectures: [x86_64]
62+
ubuntu:
63+
name: Ubuntu
64+
versions: [18.04, 20.04]
65+
architectures: [x86_64]
66+
5667
# Alpine Linux dependencies
57-
nginx_app_protect_alpine_dependencies: [
58-
boost, ca-certificates, coreutils, libelf, openssl, pcre2, zeromq,
59-
]
68+
nginx_app_protect_alpine_dependencies: [boost, ca-certificates, coreutils, libelf, openssl, pcre2, zeromq]
6069

6170
# Amazon Linux 2 extras
62-
nginx_app_protect_amazon_extras: [
63-
selinux-ng,
64-
]
71+
nginx_app_protect_amazon_extras: [selinux-ng]
6572

6673
# Debian dependencies
67-
nginx_app_protect_debian_dependencies: [
68-
apt-transport-https, ca-certificates,
69-
]
74+
nginx_app_protect_debian_dependencies: [apt-transport-https, ca-certificates]
7075

7176
# Red Hat dependencies
72-
nginx_app_protect_redhat_dependencies: [
73-
ca-certificates,
74-
"https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ((ansible_distribution == 'Amazon') | ternary('7', ansible_distribution_major_version)) }}.noarch.rpm",
75-
]
77+
nginx_app_protect_redhat_dependencies: [ca-certificates, "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ((ansible_distribution == 'Amazon') | ternary('7', ansible_distribution_major_version)) }}.noarch.rpm"]
7678

7779
# Choose where to fetch the NGINX App Protect and Security Updates signing keys from.
7880
# Default settings are the official NGINX signing key hosts.

0 commit comments

Comments
 (0)