Skip to content

Commit bc5c2f7

Browse files
committed
initial ga conversion
1 parent b852f24 commit bc5c2f7

18 files changed

+372
-148
lines changed

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,34 @@ Use `git clone https://github.com/nginxinc/ansible-role-nginx-app-protect.git` t
3737
Platforms
3838
---------
3939

40-
The NGINX Ansible role supports all platforms supported by [NGINX Plus](https://www.nginx.com/products/technical-specs/):
41-
42-
43-
**NGINX Plus**
40+
The NGINX App Protect Ansible role supports all platforms supported by [NGINX Plus](https://www.nginx.com/products/technical-specs/) that intersect with the following list:
4441

4542
```yaml
4643
CentOS:
4744
versions:
4845
- 7.4
46+
- 7.5
47+
- 7.6
48+
- 7.7
49+
- 7.8
50+
- 8.0
51+
- 8.1
52+
- 8.2
53+
Debian:
54+
versions:
55+
- 9.0
56+
- 9.1
57+
- 9.2
58+
- 9.3
59+
- 9.4
60+
- 9.5
61+
- 9.6
62+
- 9.7
63+
- 9.8
64+
- 9.9
65+
- 9.10
66+
- 9.11
67+
- 9.12
4968
```
5069
5170
Role Variables
@@ -59,7 +78,7 @@ Dependencies
5978

6079
- Since this role uses the [package_facts](https://docs.ansible.com/ansible/latest/modules/package_facts_module.html) module, on debian-based systems the `python-apt` package must be installed on targeted hosts.
6180

62-
- NGINX+ R18-R20 must already be installed on the target system
81+
- NGINX+ R19-R21 must already be installed on the target system
6382

6483
Example Playbook
6584
----------------
@@ -73,11 +92,26 @@ This is a sample playbook file for using the role to install NGINX App Protect o
7392
become: true
7493
vars:
7594
# Installs NGINX App Protect and all dependencies to the target host
76-
app_protect_install: true
95+
app_protect_enable: true
96+
97+
# Specify whether you want to maintain your version of NGINX App Protect, upgrade to the latest version, or remove NGINX App Protect.
98+
# Can be used with `app_protect_version` to achieve fine grained control on which version of NGINX App Protect is installed/used on each playbook execution.
99+
# Using 'present' will install the latest version (or 'app_protect_version') of NGINX App Protect on a fresh install.
100+
# Using 'latest' will upgrade NGINX App Protect to the latest version (that matches your 'app_protect_version') of NGINX App Protect on every playbook execution.
101+
# Using 'absent' will remove NGINX App Protect from your system.
102+
# Default is present.
103+
app_protect_state: present
104+
105+
# The installation of NGINX App Protect includes a base signature set, which may be out of date.
106+
# This option installs the latest NGINX App Protect signatures.
107+
app_protect_install_signatures: true
77108

78109
# Creates basic configuration files and enables NGINX App Protect on the target host
79110
app_protect_configure: true
80111

112+
# Removes the license (certificate and key) for the NGINX App Protect repositories on the target host(s) when playbook run is complete.
113+
app_protect_delete_license: true
114+
81115
# For use with the app_protect_configure option to determine if the default security policy will be written to the target host
82116
# Used when `app_protect_configure: true`.
83117
app_protect_security_policy_template_enable: true
@@ -90,7 +124,7 @@ This is a sample playbook file for using the role to install NGINX App Protect o
90124
# Used when `app_protect_configure: true`.
91125
app_protect_log_policy_template_enable: true
92126

93-
# Which violation types to log. Possible values: TBD
127+
# Which violation types to log. Possible values: all, illegal, blocked
94128
# Used when `app_protect_configure: true` and `app_protect_log_policy_template_enable: true`.
95129
log_policy_filter_request_type: all
96130

@@ -109,8 +143,10 @@ This is a sample playbook file for using the role to install NGINX App Protect o
109143
# Used when `nginx_conf_template_enable: true`.
110144
nginx_demo_workload: http://10.1.10.105:8080
111145

112-
# Determines whether or not to clean up tmp files created during the installation and configuration steps.
113-
cleanup_when_done: true
146+
# The location of the certificate and key to be used when downloading the packages onto the host
147+
nginx_license:
148+
certificate: "{{playbook_dir}}/license/nginx-repo.crt"
149+
key: "{{playbook_dir}}/license/nginx-repo.key"
114150

115151
roles:
116152
- role: ansible-role-nginx-app-protect

defaults/main.yml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,63 @@
11
---
22
# defaults file for ansible-role-nginx-app-protect
33

4-
app_protect_install: true
4+
# Installs NGINX App Protect and all dependencies to the target host
5+
app_protect_enable: true
6+
7+
# Specify whether you want to maintain your version of NGINX App Protect, upgrade to the latest version, or remove NGINX App Protect.
8+
# Can be used with `app_protect_version` to achieve fine grained control on which version of NGINX App Protect is installed/used on each playbook execution.
9+
# Using 'present' will install the latest version (or 'app_protect_version') of NGINX App Protect on a fresh install.
10+
# Using 'latest' will upgrade NGINX App Protect to the latest version (that matches your 'app_protect_version') of NGINX App Protect on every playbook execution.
11+
# Using 'absent' will remove NGINX App Protect from your system.
12+
# Default is present.
13+
app_protect_state: present
14+
15+
# # OPTIONAL - Installs a specific version of NGINX App Protect
16+
# app_protect_version: 20
17+
18+
# The installation of NGINX App Protect includes a base signature set, which may be out of date.
19+
# This option installs the latest NGINX App Protect signatures.
20+
app_protect_install_signatures: true
21+
22+
# Creates basic configuration files and enables NGINX App Protect on the target host
523
app_protect_configure: true
624

7-
tmp_dir: /tmp/app-protect
8-
cleanup_when_done: true
25+
# Removes the license (certificate and key) for the NGINX App Protect repositories on the target host(s) when playbook run is complete.
26+
app_protect_delete_license: true
927

10-
# Start NGINX service.
28+
# Start/Restart NGINX service when App Protect related changes are complete.
1129
# Default is true.
1230
nginx_start: true
1331

32+
# Choose where to fetch the NGINX App Protect signing key from.
33+
# Default is the official NGINX App Protect signing key host.
34+
# app_protect_signing_key: https://cs.nginx.com/static/keys/app-protect.key
35+
1436
# populate this dictionary of lists with appropriate values from the ansible_os_family and ansible_distribution_version facts
1537
app_protect_linux_families:
16-
RedHat:
38+
CentOS:
1739
- 7.4
40+
- 7.5
41+
- 7.6
42+
- 7.7
43+
- 7.8
44+
- 8.0
45+
- 8.1
46+
- 8.2
47+
Debian:
48+
- 9.0
49+
- 9.1
50+
- 9.2
51+
- 9.3
52+
- 9.4
53+
- 9.5
54+
- 9.6
55+
- 9.7
56+
- 9.8
57+
- 9.9
58+
- 9.10
59+
- 9.11
60+
- 9.12
1861

1962
app_protect_security_policy_template_enable: true
2063
app_protect_security_policy_template:
@@ -37,7 +80,7 @@ nginx_conf_template:
3780
# possible values: transparent, blocking
3881
security_policy_enforcement_mode: transparent
3982

40-
# possible values: TBD
83+
# possible values: all, illegal, blocked
4184
log_policy_filter_request_type: all
4285

4386
log_policy_syslog_target: 127.0.0.1:514

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
service:
88
name: nginx
99
state: started
10-
enabled: yes
10+
enabled: true
1111

1212
- name: "(Handler: All OSs) Reload NGINX"
1313
service:

meta/main.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ galaxy_info:
99
min_ansible_version: 2.7
1010

1111
platforms:
12-
- name: EL
12+
- name: CentOS
1313
versions:
14-
- 7.4
14+
- 7
15+
- 8
16+
- name: Debian
17+
versions:
18+
- stretch
19+
- buster
1520

1621
galaxy_tags:
1722
- waf

tasks/configure-app-protect.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
copy:
1010
src: "{{ nginx_conf_template.out_file_location }}{{ nginx_conf_template.out_file_name }}"
1111
dest: "{{ nginx_conf_template.out_file_location }}{{ nginx_conf_template.out_file_name }}.orig"
12-
remote_src: yes
12+
remote_src: true
1313
when: nginx_conf_template_enable
1414

1515
- name: "Dynamically Generate NGINX App Protect security policy file"
1616
template:
1717
src: "{{ app_protect_security_policy_template.template_file }}"
1818
dest: "{{ app_protect_security_policy_template.out_file_location }}{{ app_protect_security_policy_template.out_file_name }}"
19-
backup: yes
19+
backup: true
2020
when: app_protect_security_policy_template_enable
2121

2222
- name: "Dynamically Generate NGINX App Protect log policy file"
2323
template:
2424
src: "{{ app_protect_log_policy_template.template_file }}"
2525
dest: "{{ app_protect_log_policy_template.out_file_location }}{{ app_protect_log_policy_template.out_file_name }}"
26-
backup: yes
26+
backup: true
2727
when: app_protect_log_policy_template_enable
2828

2929
- name: "Dynamically Generate NGINX conf file"
3030
template:
3131
src: "{{ nginx_conf_template.template_file }}"
3232
dest: "{{ nginx_conf_template.out_file_location }}{{ nginx_conf_template.out_file_name }}"
33-
backup: yes
33+
backup: true
3434
when: nginx_conf_template_enable
3535

3636
- name: "Reload NGINX"

tasks/delete-license.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: "(Setup: All OSs) Set NGINX App Protect License State"
3+
set_fact:
4+
key_value: "" # appeasing the linter
5+
nginx_license_status: absent
6+
7+
- name: "(Setup: All OSs) Delete NGINX App Protect License"
8+
file:
9+
path: /etc/ssl/nginx
10+
state: absent
11+
when: ansible_distribution != "Alpine"
12+
13+
- import_tasks: setup-debian.yml
14+
when: ansible_os_family == "Debian"
15+
16+
- import_tasks: setup-redhat.yml
17+
when: ansible_os_family == "RedHat"

tasks/install-app-protect-linux.yml

Lines changed: 23 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,27 @@
11
---
2-
- name: Check that the NGINX App Protect install zip exists locally
3-
stat:
4-
path: "{{ install_zip}}"
5-
register: local_install_zip_stat
6-
connection: local
2+
- import_tasks: setup-debian.yml
3+
when: ansible_os_family == "Debian"
74

8-
- name: Check preconditions
9-
assert:
10-
that:
11-
- "local_install_zip_stat.stat.exists == true"
12-
quiet: true
5+
- import_tasks: setup-redhat.yml
6+
when: ansible_os_family == "RedHat"
137

14-
- name: Copy NGINX App Protect install zip to host
15-
copy:
16-
src: "{{ install_zip }}"
17-
dest: "{{ install_zip }}"
18-
19-
- name: Get package facts
20-
package_facts:
21-
manager: "auto"
22-
23-
- name: Set zip version number
24-
set_fact:
25-
key_value: "" # appeasing the linter
26-
app_protect_version: "{{ install_zip | regex_search('(\\d+)') }}"
27-
28-
- name: Set NGINX Plus version
29-
set_fact:
30-
key_value: "" # appeasing the linter
31-
nginx_plus_version: "{{ ansible_facts.packages['nginx-plus'] | map(attribute='version') | list | first | regex_search('^(\\d{1,3})') }}"
32-
when: "'nginx-plus' in ansible_facts.packages"
33-
34-
- name: Fail if NGINX+ version preconditions fail
35-
assert:
36-
that:
37-
- nginx_plus_version is defined
38-
- nginx_plus_version | int >= 18
39-
fail_msg: "'nginx_plus_version' release version must be a minimum of 18 for App Protect. Actual: {{ (nginx_plus_version is defined) | ternary(nginx_plus_version, 'NONE') }}"
40-
success_msg: "'nginx_plus_version' is {{ (nginx_plus_version is defined) | ternary(nginx_plus_version, 'NONE') }}"
41-
quiet: true
42-
43-
- name: Fail if app protect zip doesn't not match detected NGINX+ version
44-
assert:
45-
that:
46-
- app_protect_version is defined
47-
- nginx_plus_version | int == app_protect_version | int
48-
fail_msg: "'nginx_plus_version' {{ nginx_plus_version }} must match the NGINX App Protect version {{ app_protect_version }}"
49-
success_msg: "'nginx_plus_version' is {{ nginx_plus_version }} and 'app_protect_version' is {{ app_protect_version }}"
50-
quiet: true
51-
52-
- name: Install epel-release, unzip and openssl packages
53-
package:
54-
name: epel-release, unzip, openssl
55-
state: present
56-
57-
- name: Create a directory if it does not exist
58-
file:
59-
path: "{{ tmp_dir }}"
60-
state: directory
61-
62-
- name: Unarchive the App Protect package file that is already on the remote machine
63-
unarchive:
64-
src: "{{ install_zip }}"
65-
dest: "{{ tmp_dir }}/"
66-
remote_src: true
67-
68-
- name: Display paths of all .rpm files in dir; exclude NGINX+ installer
69-
find:
70-
paths:
71-
- "{{ tmp_dir }}"
72-
file_type: file
73-
use_regex: true
74-
patterns:
75-
- "^(?!.*nginx-plus-{{ app_protect_version }}).*\\.rpm$"
76-
register: rpm_files_dict
77-
78-
- name: Remap list to just filenames
79-
set_fact:
80-
key_value: "" # appeasing the linter
81-
rpm_files: "{{ rpm_files_dict.files | map(attribute='path' | basename) | list }}"
82-
83-
- name: Debug rpm files found
84-
debug:
85-
msg: "rpm files found: {{ rpm_files }}"
86-
verbosity: 2
87-
88-
- name: Install packages
8+
- name: "(Install: Linux) Install NGINX App Protect"
899
package:
90-
name: "{{ rpm_files }}"
91-
state: present
92-
93-
- name: Disable SELinux
94-
selinux:
95-
state: disabled
96-
97-
- name: "Start NGINX App Protect"
98-
service:
99-
name: nginx-app-protect
100-
state: started
101-
enabled: yes
102-
when:
103-
- not ansible_check_mode
104-
105-
- name: "Start NGINX"
106-
service:
107-
name: nginx
108-
state: reloaded
109-
when:
110-
- not ansible_check_mode
111-
112-
- name: Recursively remove extracted directory
113-
file:
114-
path: "{{ tmp_dir }}"
115-
state: absent
116-
when: cleanup_when_done
117-
118-
- name: Remove source zip
119-
file:
120-
path: "{{ install_zip }}"
121-
state: absent
122-
when: cleanup_when_done
10+
name: "app-protect{{ nginx_version | default('') }}"
11+
state: "{{ app_protect_state }}"
12+
notify: "(Handler: All OSs) Start NGINX"
13+
14+
# - name: "Start NGINX App Protect"
15+
# service:
16+
# name: nginx-app-protect
17+
# state: started
18+
# enabled: true
19+
# when:
20+
# - not ansible_check_mode
21+
22+
# - name: "Start NGINX"
23+
# service:
24+
# name: nginx
25+
# state: reloaded
26+
# when:
27+
# - not ansible_check_mode

0 commit comments

Comments
 (0)