Skip to content

Commit 6e1a074

Browse files
committed
feat: Add Ansible/Jinja2/Collections validation (#456)
1 parent 935472f commit 6e1a074

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
FEATURES:
66

7+
- Add validation tasks to check the Ansible version, the Jinja2 version, and whether the required Ansible collections for this role are installed.
78
- 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`.
89

910
BUG FIXES:

Diff for: tasks/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
- name: Validate Ansible/Jinja2 version and Ansible collections
3+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate/validate.yml"
4+
tags: nginx_config_validate
5+
26
- name: Set up SELinux
37
ansible.builtin.include_tasks: "{{ role_path }}/tasks/prerequisites/setup-selinux.yml"
48
when:

Diff for: tasks/validate/validate.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
- name: Verify you are using a supported Ansible version on your Ansible host
3+
ansible.builtin.assert:
4+
that: ansible_version['full'] is version(nginx_config_ansible_version, '>=')
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
8+
ignore_errors: true # noqa ignore-errors
9+
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(nginx_config_jinja2_version, '>=')
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: Verify that the 'community.general' and 'ansible.posix' Ansible collections are installed on your Ansible host
26+
when: nginx_config_selinux | bool
27+
delegate_to: localhost
28+
become: false
29+
block:
30+
- name: Extract the list of Ansible collections installed on your Ansible host
31+
ansible.builtin.command: ansible-galaxy collection list
32+
register: collection_list
33+
changed_when: false
34+
35+
- name: Verify that the 'community.general' Ansible collection is installed on your Ansible host
36+
ansible.builtin.assert:
37+
that: collection_list is search('community.general')
38+
success_msg: The 'community.general' Ansible collection is installed.
39+
fail_msg: The 'community.general' Ansible collection is not installed. Please install the 'community.general' Ansible collection. Check the README for more details.
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.

Diff for: vars/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
---
2+
# Set the minimum version required for Ansible and Jinja2
3+
nginx_config_ansible_version: 2.16
4+
nginx_config_jinja2_version: 3.1

0 commit comments

Comments
 (0)