From 0573356d160deb5bc50780252a5969a7389a022b Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Mon, 9 Jan 2023 18:33:50 +0100 Subject: [PATCH] ansible: Use assert on checks for readability assert will also fail when we're not meeting the conditions, makes clear what we're actually testing, and isn't listed as a skipped task when the condition is ok. Change-Id: I20a48bb2eaa3715c6351f5ede04c191ea0a10d3d --- ansible/roles/prechecks/tasks/package_checks.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ansible/roles/prechecks/tasks/package_checks.yml b/ansible/roles/prechecks/tasks/package_checks.yml index 272f9cbed7..3ce88f37c0 100644 --- a/ansible/roles/prechecks/tasks/package_checks.yml +++ b/ansible/roles/prechecks/tasks/package_checks.yml @@ -12,11 +12,13 @@ # to check. as ansible_version does not provide major.minor in dict, we need to # set it as variable. - name: Checking Ansible version - vars: - ansible_version_host: "{{ ansible_version.major }}.{{ ansible_version.minor }}" - fail: - msg: >- + assert: + that: + - ansible_version_host is version(ansible_version_min, '>=') + - ansible_version_host is version(ansible_version_max, '<=') + fail_msg: >- Ansible version should be between {{ ansible_version_min }} and {{ ansible_version_max }}. Current version is {{ ansible_version.full }} which is not supported. + vars: + ansible_version_host: "{{ ansible_version.major }}.{{ ansible_version.minor }}" run_once: true - when: ansible_version_host is version(ansible_version_min, '<') or ansible_version_host is version(ansible_version_max, '>')