From 48ef36015e4b2fd0a6516e190402959e0ab7e393 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 29 Jul 2024 03:32:04 -0800 Subject: [PATCH 1/2] feat: Add Ansible/Jinja2/Collections validation (#456) --- CHANGELOG.md | 1 + tasks/validate/validate.yml | 45 +++++++++++++++++++++++++++++++++++++ vars/main.yml | 3 +++ 3 files changed, 49 insertions(+) create mode 100644 tasks/validate/validate.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 378bfa2c..6dacfba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ FEATURES: +- Add validation tasks to check the Ansible version, the Jinja2 version, and whether the required Ansible collections for this role are installed. - 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`. BUG FIXES: diff --git a/tasks/validate/validate.yml b/tasks/validate/validate.yml new file mode 100644 index 00000000..b9694f06 --- /dev/null +++ b/tasks/validate/validate.yml @@ -0,0 +1,45 @@ +--- +- name: Verify you are using a supported Ansible version on your Ansible host + ansible.builtin.assert: + that: ansible_version['full'] is version(nginx_config_ansible_version, '>=') + success_msg: Ansible {{ ansible_version['full'] }} is supported. + 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. + delegate_to: localhost + ignore_errors: true # noqa ignore-errors + +- name: Extract the version of Jinja2 installed on your Ansible host + ansible.builtin.command: ansible --version + register: jinja2_version + changed_when: false + delegate_to: localhost + become: false + +- name: Verify that you are using a supported Jinja2 version on your Ansible host + ansible.builtin.assert: + that: (jinja2_version['stdout'] | regex_search('jinja version = ([\\d.]+)', '\\1') | first) is version(nginx_config_jinja2_version, '>=') + success_msg: Jinja2 {{ jinja2_version['stdout'] | regex_search('jinja version = ([\d.]+)', '\1') | first }} is supported. + 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. + delegate_to: localhost + become: false + +- name: Verify that the 'community.general' and 'ansible.posix' Ansible collections are installed on your Ansible host + when: nginx_config_selinux | bool + delegate_to: localhost + become: false + block: + - name: Extract the list of Ansible collections installed on your Ansible host + ansible.builtin.command: ansible-galaxy collection list + register: collection_list + changed_when: false + + - name: Verify that the 'community.general' Ansible collection is installed on your Ansible host + ansible.builtin.assert: + that: collection_list is search('community.general') + success_msg: The 'community.general' Ansible collection is installed. + fail_msg: The 'community.general' Ansible collection is not installed. Please install the 'community.general' Ansible collection. Check the README for more details. + + - name: Verify that the 'ansible.posix' Ansible collection is installed on your Ansible host + ansible.builtin.assert: + that: lookup('community.general.collection_version', 'ansible.posix') != 'none' + success_msg: The 'ansible.posix' Ansible collection is installed. + fail_msg: The 'ansible.posix' Ansible collection is not installed. Please install the 'ansible.posix' Ansible collection. Check the README for more details. diff --git a/vars/main.yml b/vars/main.yml index ed97d539..410ec43b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1 +1,4 @@ --- +# Set the minimum version required for Ansible and Jinja2 +nginx_config_ansible_version: 2.16 +nginx_config_jinja2_version: 3.1 From c1b97297c2452d22f279ecf4e38988000daaa563 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:54:09 +0000 Subject: [PATCH 2/2] Bump ansible-core in /.github/workflows/requirements Bumps [ansible-core](https://github.com/ansible/ansible) from 2.16.6 to 2.17.2. - [Release notes](https://github.com/ansible/ansible/releases) - [Commits](https://github.com/ansible/ansible/compare/v2.16.6...v2.17.2) --- updated-dependencies: - dependency-name: ansible-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/requirements/requirements_ansible_lint.txt | 2 +- .github/workflows/requirements/requirements_galaxy.txt | 2 +- .github/workflows/requirements/requirements_molecule.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/requirements/requirements_ansible_lint.txt b/.github/workflows/requirements/requirements_ansible_lint.txt index 515a516d..a551db79 100644 --- a/.github/workflows/requirements/requirements_ansible_lint.txt +++ b/.github/workflows/requirements/requirements_ansible_lint.txt @@ -1,4 +1,4 @@ -ansible-core==2.16.6 +ansible-core==2.17.2 ansible-compat==24.7.0 yamllint==1.35.1 ansible-lint==24.7.0 diff --git a/.github/workflows/requirements/requirements_galaxy.txt b/.github/workflows/requirements/requirements_galaxy.txt index 9ba8b8e8..2ec2e5c5 100644 --- a/.github/workflows/requirements/requirements_galaxy.txt +++ b/.github/workflows/requirements/requirements_galaxy.txt @@ -1,2 +1,2 @@ -ansible-core==2.16.6 +ansible-core==2.17.2 jinja2==3.1.4 diff --git a/.github/workflows/requirements/requirements_molecule.txt b/.github/workflows/requirements/requirements_molecule.txt index 40700015..2cd5d55e 100644 --- a/.github/workflows/requirements/requirements_molecule.txt +++ b/.github/workflows/requirements/requirements_molecule.txt @@ -1,4 +1,4 @@ -ansible-core==2.16.6 +ansible-core==2.17.2 jinja2==3.1.4 ansible-compat==24.7.0 molecule==24.7.0