Skip to content

Commit 46d5f55

Browse files
authored
feat: Add Ansible/Jinja2/Collections validation (#747)
1 parent 7a1b331 commit 46d5f55

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

CHANGELOG.md

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

1212
- Add support for installing NGINX Open Source on Alpine Linux 3.20.
1313
- Add support for installing NGINX Agent on Ubuntu noble.
14+
- Add validation tasks to check the Ansible version, the Jinja2 version, and whether the required Ansible collections for this role are installed.
1415
- Bump the Ansible `community.general` collection to `9.2.0`, `community.crypto` collection to `2.21.1` and `community.docker` collection to `3.11.0`.
1516

1617
DOCUMENTATION:

tasks/validate/validate.yml

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,89 @@
11
---
2-
- name: Check whether you are using a supported NGINX distribution
2+
- name: Verify you are using a supported Ansible version on your Ansible host
33
ansible.builtin.assert:
4-
that:
5-
- ansible_facts['distribution'] | lower in nginx_distributions.keys() | list
6-
- (ansible_facts['distribution_version'] | regex_search('\\d{1,2}\\.\\d{2}') | float in nginx_distributions[ansible_facts['distribution'] | lower]['versions'] | map('float') if ansible_facts['distribution'] | lower in ['alpine', 'ubuntu'] else ansible_facts['distribution_major_version'] in nginx_distributions[ansible_facts['distribution'] | lower]['versions'] | string)
7-
- ansible_facts['architecture'] in nginx_distributions[ansible_facts['distribution'] | lower]['architectures']
8-
success_msg: Your distribution, {{ nginx_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is supported by NGINX {{ (nginx_type == 'opensource') | ternary('Open Source', 'Plus') }}.
9-
fail_msg: Your distribution, {{ nginx_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is not supported by NGINX {{ (nginx_type == 'opensource') | ternary('Open Source', 'Plus') }}.
10-
when:
11-
- nginx_enable | bool
12-
- (nginx_install_from == "nginx_repository" or nginx_type == "plus")
4+
that: ansible_version['full'] is version('2.16', '>=')
5+
success_msg: Ansible {{ ansible_version['full'] }} is supported.
6+
fail_msg: Ansible {{ ansible_version['full'] }} has reached End of Life (EoL). Please upgrade to a supported Ansible release. Check the README for more details.
7+
delegate_to: localhost
138
ignore_errors: true # noqa ignore-errors
149

15-
- name: Check that 'nginx_setup' is an allowed value
10+
- name: Extract the version of Jinja2 installed on your Ansible host
11+
ansible.builtin.command: ansible --version
12+
register: jinja2_version
13+
changed_when: false
14+
delegate_to: localhost
15+
16+
- name: Verify that you are using a supported Jinja2 version on your Ansible host
17+
ansible.builtin.assert:
18+
that: (jinja2_version['stdout'] | regex_search('jinja version = ([\\d.]+)', '\\1') | first) is version('3.1', '>=')
19+
success_msg: Jinja2 {{ jinja2_version['stdout'] | regex_search('jinja version = ([\d.]+)', '\1') | first }} is supported.
20+
fail_msg: Jinja2 {{ jinja2_version['stdout'] | regex_search('jinja version = ([\d.]+)', '\1') | first }} is not supported. Please upgrade to Jinja2 3.1. Check the README for more details.
21+
delegate_to: localhost
22+
23+
- name: Extract the list of Ansible collections installed on your Ansible host
24+
ansible.builtin.command: ansible-galaxy collection list
25+
register: collection_list
26+
changed_when: false
27+
delegate_to: localhost
28+
29+
- name: Verify that the 'community.general' Ansible collection is installed on your Ansible host
30+
ansible.builtin.assert:
31+
that: collection_list is search('community.general')
32+
success_msg: The 'community.general' Ansible collection is installed.
33+
fail_msg: The 'community.general' Ansible collection is not installed. Please install the 'community.general' Ansible collection. Check the README for more details.
34+
changed_when: false
35+
delegate_to: localhost
36+
37+
- name: Verify that the 'ansible.posix' Ansible collection is installed on your Ansible host
38+
ansible.builtin.assert:
39+
that: lookup('community.general.collection_version', 'ansible.posix') != 'none'
40+
success_msg: The 'ansible.posix' Ansible collection is installed.
41+
fail_msg: The 'ansible.posix' Ansible collection is not installed. Please install the 'ansible.posix' Ansible collection. Check the README for more details.
42+
delegate_to: localhost
43+
when: nginx_selinux | bool
44+
45+
- name: Verify that the 'community.crypto' Ansible collection is installed on your Ansible host
46+
ansible.builtin.assert:
47+
that: lookup('community.general.collection_version', 'community.crypto') != 'none'
48+
success_msg: The 'community.crypto' Ansible collection is installed.
49+
fail_msg: The 'community.crypto' Ansible collection is not installed. Please install the 'community.crypto' Ansible collection. Check the README for more details.
50+
delegate_to: localhost
51+
when: nginx_type == 'plus'
52+
53+
- name: Verify that 'nginx_setup' parameter is a valid value
1654
ansible.builtin.assert:
1755
that: nginx_setup in nginx_setup_vars
18-
fail_msg: The value you used for 'nginx_setup', {{ nginx_setup }}, is not allowed. The allowed values are [{{ nginx_setup_vars | join(', ') }}].
56+
success_msg: The value you used for 'nginx_setup', {{ nginx_setup }}, is valid.
57+
fail_msg: The value you used for 'nginx_setup', {{ nginx_setup }}, is not valid. The valid values are [{{ nginx_setup_vars | join(', ') }}].
58+
delegate_to: localhost
1959
when: nginx_enable | bool
2060
ignore_errors: true # noqa ignore-errors
2161

22-
- name: Check that 'nginx_branch' is an allowed value
62+
- name: Verify that 'nginx_branch' parameter is a valid value
2363
ansible.builtin.assert:
2464
that: nginx_branch in nginx_branch_vars
25-
fail_msg: The value you used for 'nginx_branch', {{ nginx_branch }}, is not allowed. The allowed values are [{{ nginx_branch_vars | join(', ') }}].
65+
success_msg: The value you used for 'nginx_branch', {{ nginx_branch }}, is valid.
66+
fail_msg: The value you used for 'nginx_branch', {{ nginx_branch }}, is not allowed. The valid values are [{{ nginx_branch_vars | join(', ') }}].
2667
when: nginx_enable | bool
2768
ignore_errors: true # noqa ignore-errors
2869

29-
- name: Check that 'nginx_install_from' is an allowed value
70+
- name: Verify that 'nginx_install_from' parameter is a valid value
3071
ansible.builtin.assert:
3172
that: nginx_install_from in nginx_install_from_vars
32-
fail_msg: The value you used for 'nginx_install_from', {{ nginx_install_from }}, is not allowed. The allowed values are [{{ nginx_install_from_vars | join(', ') }}].
73+
success_msg: The value you used for 'nginx_install_from', {{ nginx_install_from }} is valid.
74+
fail_msg: The value you used for 'nginx_install_from', {{ nginx_install_from }}, is not valid. The valid values are [{{ nginx_install_from_vars | join(', ') }}].
3375
when: nginx_enable | bool
3476
ignore_errors: true # noqa ignore-errors
77+
78+
- name: Verify whether you are using a supported NGINX distribution
79+
ansible.builtin.assert:
80+
that:
81+
- ansible_facts['distribution'] | lower in nginx_distributions.keys() | list
82+
- (ansible_facts['distribution_version'] | regex_search('\\d{1,2}\\.\\d{2}') | float in nginx_distributions[ansible_facts['distribution'] | lower]['versions'] | map('float') if ansible_facts['distribution'] | lower in ['alpine', 'ubuntu'] else ansible_facts['distribution_major_version'] in nginx_distributions[ansible_facts['distribution'] | lower]['versions'] | string)
83+
- ansible_facts['architecture'] in nginx_distributions[ansible_facts['distribution'] | lower]['architectures']
84+
success_msg: Your distribution, {{ nginx_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is supported by NGINX {{ (nginx_type == 'opensource') | ternary('Open Source', 'Plus') }}.
85+
fail_msg: Your distribution, {{ nginx_distributions[ansible_facts['distribution'] | lower]['name'] }} {{ ansible_facts['distribution_version'] }} ({{ ansible_facts['architecture'] }}), is not supported by NGINX {{ (nginx_type == 'opensource') | ternary('Open Source', 'Plus') }}.
86+
when:
87+
- nginx_enable | bool
88+
- (nginx_install_from == "nginx_repository" or nginx_type == "plus")
89+
ignore_errors: true # noqa ignore-errors

0 commit comments

Comments
 (0)