From e35a6e5c0c047a4797aad82142ace5be03fabe3c Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 27 Mar 2024 17:13:35 -0600 Subject: [PATCH] Refactor package hold verification tests --- molecule/hold/verify.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/molecule/hold/verify.yml b/molecule/hold/verify.yml index 34b8d09..496c4da 100644 --- a/molecule/hold/verify.yml +++ b/molecule/hold/verify.yml @@ -78,27 +78,31 @@ ansible.builtin.package_facts: - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}" + success_msg: "Found {{ _package }}={{ _version }}" vars: _package: "{{ item.split('=') | first }}" _version: "{{ item.split('=') | last }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" loop: "{{ postgresql_package_list }}" - when: - - ansible_os_family == "Debian" - - _package not in packages or _version != _installed + when: ansible_os_family == "Debian" - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}" + success_msg: "Found {{ _package }}={{ _version }}" vars: _prefix: "^{{ _package }}-" _suffix: "-.*$" _package: "{{ item.0 }}" _version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" - loop: "{{ postgresql_package_list | zip(_postgresql_package_name) }}" - when: - - ansible_os_family == "RedHat" - - _package not in packages or _version != _installed + loop: "{{ _postgresql_package_name | zip(postgresql_package_list) }}" + when: ansible_os_family == "RedHat"