Skip to content

Commit 0d2bb59

Browse files
authored
Standardize code from dot to array notation (#306)
1 parent fddb4bc commit 0d2bb59

File tree

14 files changed

+91
-102
lines changed

14 files changed

+91
-102
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Changelog
22

3-
## 0.5.3 (Unreleased)
3+
## 0.6.0 (Unreleased)
44

55
ENHANCEMENTS:
66

7+
* Standardize code from dot to array notation to keep in with the standards set by the other roles in the Ansible NGINX core collection.
78
* Bump the minimum version of Ansible core required to run the role to `2.12` (`2.11` is no longer supported by Ansible).
89
* Support the `include` directive in the main NGINX context.
910
* Bump the Ansible `community.general` collection to `6.2.0` and `community.docker` collection to `3.4.0`.
@@ -16,7 +17,7 @@ BUG FIXES:
1617
TESTS:
1718

1819
* Update GitHub actions to run on Ubuntu 22.04 (and thus support `cgroups` v2).
19-
* Explicitly specify `amd64` as the platform used in Molecule tests. This will ensure that tests work as expected when run on different host architectures (e.g. newer Macbooks with `arm` processors).
20+
* Explicitly specify `amd64` as the platform used in NGINX Plus Molecule tests. This will ensure that tests involving NGINX App Protect will work as expected when run on different host architectures (e.g. newer Macbooks with `arm` processors).
2021

2122
## 0.5.2 (October 17, 2022)
2223

handlers/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
- name: (Handler - NGINX Config) Print NGINX error if syntax check fails
1313
ansible.builtin.debug:
14-
var: config_check.stderr_lines
15-
failed_when: config_check.rc != 0
14+
var: config_check['stderr_lines']
15+
failed_when: config_check['rc'] != 0
1616
when:
17-
- config_check.stderr_lines is defined
18-
- config_check.stderr_lines != []
19-
- config_check.rc != 0
17+
- config_check['stderr_lines'] is defined
18+
- config_check['stderr_lines'] != []
19+
- config_check['rc'] != 0
2020
listen: (Handler - NGINX Config) Run NGINX
2121

2222
- name: (Handler - NGINX Config) Start/reload NGINX

molecule/cleanup_module/molecule.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,30 @@ lint: |
1111
platforms:
1212
- name: alpine-3.17
1313
image: alpine:3.17
14-
platform: amd64
1514
dockerfile: ../common/Dockerfile.j2
1615
privileged: true
1716
cgroupns_mode: host
1817
volumes:
1918
- /sys/fs/cgroup:/sys/fs/cgroup:rw
2019
command: /sbin/init
21-
- name: rhel-9
22-
image: redhat/ubi9:9.1.0
23-
platform: amd64
20+
- name: debian-bullseye
21+
image: debian:bullseye-slim
2422
dockerfile: ../common/Dockerfile.j2
2523
privileged: true
2624
cgroupns_mode: host
2725
volumes:
2826
- /sys/fs/cgroup:/sys/fs/cgroup:rw
29-
command: /usr/sbin/init
30-
- name: debian-bullseye
31-
image: debian:bullseye-slim
32-
platform: amd64
27+
command: /sbin/init
28+
- name: rhel-9
29+
image: redhat/ubi9:9.1.0
3330
dockerfile: ../common/Dockerfile.j2
3431
privileged: true
3532
cgroupns_mode: host
3633
volumes:
3734
- /sys/fs/cgroup:/sys/fs/cgroup:rw
38-
command: /sbin/init
35+
command: /usr/sbin/init
3936
- name: ubuntu-jammy
4037
image: ubuntu:jammy
41-
platform: amd64
4238
dockerfile: ../common/Dockerfile.j2
4339
privileged: true
4440
cgroupns_mode: host

molecule/cleanup_module/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
path: /etc/nginx/conf.d/default.conf
2525
check_mode: true
2626
register: stat_result
27-
failed_when: stat_result.stat.exists
27+
failed_when: stat_result['stat']['exists'] | bool
2828

2929
- name: Check mock.conf does not exist
3030
ansible.builtin.stat:
3131
path: /etc/nginx/conf.d/mock.conf
3232
check_mode: true
3333
register: stat_result
34-
failed_when: stat_result.stat.exists
34+
failed_when: stat_result['stat']['exists'] | bool

molecule/default/molecule.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,30 @@ lint: |
1111
platforms:
1212
- name: alpine-3.17
1313
image: alpine:3.17
14-
platform: amd64
1514
dockerfile: ../common/Dockerfile.j2
1615
privileged: true
1716
cgroupns_mode: host
1817
volumes:
1918
- /sys/fs/cgroup:/sys/fs/cgroup:rw
2019
command: /sbin/init
21-
- name: rhel-9
22-
image: redhat/ubi9:9.1.0
23-
platform: amd64
20+
- name: debian-bullseye
21+
image: debian:bullseye-slim
2422
dockerfile: ../common/Dockerfile.j2
2523
privileged: true
2624
cgroupns_mode: host
2725
volumes:
2826
- /sys/fs/cgroup:/sys/fs/cgroup:rw
29-
command: /usr/sbin/init
30-
- name: debian-bullseye
31-
image: debian:bullseye-slim
32-
platform: amd64
27+
command: /sbin/init
28+
- name: rhel-9
29+
image: redhat/ubi9:9.1.0
3330
dockerfile: ../common/Dockerfile.j2
3431
privileged: true
3532
cgroupns_mode: host
3633
volumes:
3734
- /sys/fs/cgroup:/sys/fs/cgroup:rw
38-
command: /sbin/init
35+
command: /usr/sbin/init
3936
- name: ubuntu-jammy
4037
image: ubuntu:jammy
41-
platform: amd64
4238
dockerfile: ../common/Dockerfile.j2
4339
privileged: true
4440
cgroupns_mode: host

molecule/default/verify.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,42 @@
2424
url: http://localhost
2525
return_content: true
2626
register: this
27-
failed_when: "'Hello World' not in this.content"
27+
failed_when: "'Hello World' not in this['content']"
2828

2929
- name: Check client body cache directory exists
3030
ansible.builtin.stat:
3131
path: /var/cache/nginx/client
3232
check_mode: true
3333
register: stat_result
34-
failed_when: not stat_result.stat.exists
34+
failed_when: not stat_result['stat']['exists'] | bool
3535

3636
- name: Check proxy cache directory exists
3737
ansible.builtin.stat:
3838
path: /var/cache/nginx/proxy
3939
check_mode: true
4040
register: stat_result
41-
failed_when: not stat_result.stat.exists
41+
failed_when: not stat_result['stat']['exists'] | bool
4242

4343
- name: Check default.conf exists
4444
ansible.builtin.stat:
4545
path: /etc/nginx/conf.d/default.conf
4646
check_mode: true
4747
register: stat_result
48-
failed_when: not stat_result.stat.exists
48+
failed_when: not stat_result['stat']['exists'] | bool
4949

5050
- name: Check frontend_default.conf exists
5151
ansible.builtin.stat:
5252
path: /etc/nginx/conf.d/frontend_default.conf
5353
check_mode: true
5454
register: stat_result
55-
failed_when: not stat_result.stat.exists
55+
failed_when: not stat_result['stat']['exists'] | bool
5656

5757
- name: Check backend_default.conf exists
5858
ansible.builtin.stat:
5959
path: /etc/nginx/conf.d/backend/backend_default.conf
6060
check_mode: true
6161
register: stat_result
62-
failed_when: not stat_result.stat.exists
62+
failed_when: not stat_result['stat']['exists'] | bool
6363

6464
- name: Ensure default.conf contains 'location /'
6565
ansible.builtin.lineinfile:

molecule/plus/verify.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,48 @@
2020
failed_when: (service is changed) or (service is failed)
2121

2222
- name: Functional tests
23-
when: ansible_os_family != "Alpine"
23+
when: ansible_facts['os_family'] != 'Alpine'
2424
block:
2525
- name: Check that a page returns a status 200 and fail if the words Hello World are not in the page contents
2626
ansible.builtin.uri:
2727
url: http://localhost
2828
return_content: true
2929
register: this
30-
failed_when: "'Hello World' not in this.content"
30+
failed_when: "'Hello World' not in this['content']"
3131

3232
- name: Check that a page returns a status 200 and fail if the words Request Rejected are not in the page contents
3333
ansible.builtin.uri:
3434
url: http://localhost/?v=<script>
3535
return_content: true
3636
register: this
37-
failed_when: "'Request Rejected' not in this.content"
37+
failed_when: "'Request Rejected' not in this['content']"
3838

3939
- name: Ensure /var/log/messages contains block event from above test
4040
ansible.builtin.shell: grep -c "Non-browser Client,Abuse of Functionality,Cross Site Scripting (XSS)" /var/log/messages || true
4141
register: event
4242
changed_when: false
43-
failed_when: event.stdout == "0"
43+
failed_when: event['stdout'] == '0'
4444

4545
- name: Check default.conf exists
4646
ansible.builtin.stat:
4747
path: /etc/nginx/conf.d/default.conf
4848
check_mode: true
4949
register: stat_result
50-
failed_when: not stat_result.stat.exists
50+
failed_when: not stat_result['stat']['exists'] | bool
5151

5252
- name: Check frontend_default.conf exists
5353
ansible.builtin.stat:
5454
path: /etc/nginx/conf.d/frontend_default.conf
5555
check_mode: true
5656
register: stat_result
57-
failed_when: not stat_result.stat.exists
57+
failed_when: not stat_result['stat']['exists'] | bool
5858

5959
- name: Check backend_default.conf exists
6060
ansible.builtin.stat:
6161
path: /etc/nginx/conf.d/backend_default.conf
6262
check_mode: true
6363
register: stat_result
64-
failed_when: not stat_result.stat.exists
64+
failed_when: not stat_result['stat']['exists'] | bool
6565

6666
- name: Ensure default.conf contains 'location /'
6767
ansible.builtin.lineinfile:

molecule/stable_push/molecule.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,30 @@ lint: |
1111
platforms:
1212
- name: alpine-3.17
1313
image: alpine:3.17
14-
platform: amd64
1514
dockerfile: ../common/Dockerfile.j2
1615
privileged: true
1716
cgroupns_mode: host
1817
volumes:
1918
- /sys/fs/cgroup:/sys/fs/cgroup:rw
2019
command: /sbin/init
21-
- name: rhel-9
22-
image: redhat/ubi9:9.1.0
23-
platform: amd64
20+
- name: debian-bullseye
21+
image: debian:bullseye-slim
2422
dockerfile: ../common/Dockerfile.j2
2523
privileged: true
2624
cgroupns_mode: host
2725
volumes:
2826
- /sys/fs/cgroup:/sys/fs/cgroup:rw
29-
command: /usr/sbin/init
30-
- name: debian-bullseye
31-
image: debian:bullseye-slim
32-
platform: amd64
27+
command: /sbin/init
28+
- name: rhel-9
29+
image: redhat/ubi9:9.1.0
3330
dockerfile: ../common/Dockerfile.j2
3431
privileged: true
3532
cgroupns_mode: host
3633
volumes:
3734
- /sys/fs/cgroup:/sys/fs/cgroup:rw
38-
command: /sbin/init
35+
command: /usr/sbin/init
3936
- name: ubuntu-jammy
4037
image: ubuntu:jammy
41-
platform: amd64
4238
dockerfile: ../common/Dockerfile.j2
4339
privileged: true
4440
cgroupns_mode: host

molecule/stable_push/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
path: /etc/nginx/conf.d/default.conf
3030
check_mode: true
3131
register: stat_result
32-
failed_when: not stat_result.stat.exists
32+
failed_when: not stat_result['stat']['exists'] | bool
3333

3434
- name: Ensure default.conf contains 'location /'
3535
ansible.builtin.lineinfile:
@@ -45,4 +45,4 @@
4545
path: /etc/nginx/snippets/location_snippet.conf
4646
check_mode: true
4747
register: stat_result
48-
failed_when: not stat_result.stat.exists
48+
failed_when: not stat_result['stat']['exists'] | bool

tasks/config/cleanup-config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
- name: Find NGINX config files
33
ansible.builtin.find:
4-
paths: "{{ item.directory }}"
4+
paths: "{{ item['directory'] }}"
55
patterns: "*.conf"
6-
recurse: "{{ item.recurse | default(false) }}"
6+
recurse: "{{ item['recurse'] | default(false) }}"
77
loop: "{{ nginx_config_cleanup_paths }}"
88
when: nginx_config_cleanup_paths is defined
99
register: nginx_config_files
@@ -12,5 +12,5 @@
1212
ansible.builtin.file:
1313
path: "{{ item }}"
1414
state: absent
15-
loop: "{{ nginx_config_files.results | map(attribute='files') | sum(start=[]) | map(attribute='path') | list + nginx_config_cleanup_files | default('') | list }}"
15+
loop: "{{ nginx_config_files['results'] | map(attribute='files') | sum(start=[]) | map(attribute='path') | list + nginx_config_cleanup_files | default('') | list }}"
1616
notify: (Handler - NGINX Config) Run NGINX

0 commit comments

Comments
 (0)