Skip to content

Commit a6712e3

Browse files
committed
feat: Add Ansible/Jinja2/Collections validation (#747)
1 parent 7a1b331 commit a6712e3

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-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: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,100 @@
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+
become: false
16+
17+
- name: Verify that you are using a supported Jinja2 version on your Ansible host
18+
ansible.builtin.assert:
19+
that: (jinja2_version['stdout'] | regex_search('jinja version = ([\\d.]+)', '\\1') | first) is version('3.1', '>=')
20+
success_msg: Jinja2 {{ jinja2_version['stdout'] | regex_search('jinja version = ([\d.]+)', '\1') | first }} is supported.
21+
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.
22+
delegate_to: localhost
23+
become: false
24+
25+
- name: Extract the list of Ansible collections installed on your Ansible host
26+
ansible.builtin.command: ansible-galaxy collection list
27+
register: collection_list
28+
changed_when: false
29+
delegate_to: localhost
30+
become: false
31+
32+
- name: Verify that the 'community.general' Ansible collection is installed on your Ansible host
33+
ansible.builtin.assert:
34+
that: collection_list is search('community.general')
35+
success_msg: The 'community.general' Ansible collection is installed.
36+
fail_msg: The 'community.general' Ansible collection is not installed. Please install the 'community.general' Ansible collection. Check the README for more details.
37+
changed_when: false
38+
delegate_to: localhost
39+
become: false
40+
41+
- name: Verify that the 'ansible.posix' Ansible collection is installed on your Ansible host
42+
ansible.builtin.assert:
43+
that: lookup('community.general.collection_version', 'ansible.posix') != 'none'
44+
success_msg: The 'ansible.posix' Ansible collection is installed.
45+
fail_msg: The 'ansible.posix' Ansible collection is not installed. Please install the 'ansible.posix' Ansible collection. Check the README for more details.
46+
delegate_to: localhost
47+
become: false
48+
when: nginx_selinux | bool
49+
50+
- name: Verify that the 'community.crypto' Ansible collection is installed on your Ansible host
51+
ansible.builtin.assert:
52+
that: lookup('community.general.collection_version', 'community.crypto') != 'none'
53+
success_msg: The 'community.crypto' Ansible collection is installed.
54+
fail_msg: The 'community.crypto' Ansible collection is not installed. Please install the 'community.crypto' Ansible collection. Check the README for more details.
55+
delegate_to: localhost
56+
become: false
57+
when: nginx_type == 'plus'
58+
59+
- name: Verify that 'nginx_setup' parameter is a valid value
1660
ansible.builtin.assert:
1761
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(', ') }}].
62+
success_msg: The value you used for 'nginx_setup', {{ nginx_setup }}, is valid.
63+
fail_msg: The value you used for 'nginx_setup', {{ nginx_setup }}, is not valid. The valid values are [{{ nginx_setup_vars | join(', ') }}].
64+
delegate_to: localhost
65+
become: false
1966
when: nginx_enable | bool
2067
ignore_errors: true # noqa ignore-errors
2168

22-
- name: Check that 'nginx_branch' is an allowed value
69+
- name: Verify that 'nginx_branch' parameter is a valid value
2370
ansible.builtin.assert:
2471
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(', ') }}].
72+
success_msg: The value you used for 'nginx_branch', {{ nginx_branch }}, is valid.
73+
fail_msg: The value you used for 'nginx_branch', {{ nginx_branch }}, is not allowed. The valid values are [{{ nginx_branch_vars | join(', ') }}].
74+
delegate_to: localhost
75+
become: false
2676
when: nginx_enable | bool
2777
ignore_errors: true # noqa ignore-errors
2878

29-
- name: Check that 'nginx_install_from' is an allowed value
79+
- name: Verify that 'nginx_install_from' parameter is a valid value
3080
ansible.builtin.assert:
3181
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(', ') }}].
82+
success_msg: The value you used for 'nginx_install_from', {{ nginx_install_from }} is valid.
83+
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(', ') }}].
84+
delegate_to: localhost
85+
become: false
3386
when: nginx_enable | bool
3487
ignore_errors: true # noqa ignore-errors
88+
89+
- name: Verify whether you are using a supported NGINX distribution
90+
ansible.builtin.assert:
91+
that:
92+
- ansible_facts['distribution'] | lower in nginx_distributions.keys() | list
93+
- (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)
94+
- ansible_facts['architecture'] in nginx_distributions[ansible_facts['distribution'] | lower]['architectures']
95+
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') }}.
96+
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') }}.
97+
when:
98+
- nginx_enable | bool
99+
- (nginx_install_from == "nginx_repository" or nginx_type == "plus")
100+
ignore_errors: true # noqa ignore-errors

0 commit comments

Comments
 (0)