From 6966b53b5be48cbcef600f53fb58a5c5b478a185 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 8 Jul 2024 23:25:49 +0200 Subject: [PATCH] dnf - arches must be the same in the is_newer_installed check (#83417) (#83504) Fixes #83406 (cherry picked from commit 2930a4664c2b4ac3c8b1127c91d98d53644e61cf) --- .../fragments/83406-dnf-fix-arch-cmp.yml | 2 ++ lib/ansible/modules/dnf.py | 2 +- test/integration/targets/dnf/tasks/repo.yml | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/83406-dnf-fix-arch-cmp.yml diff --git a/changelogs/fragments/83406-dnf-fix-arch-cmp.yml b/changelogs/fragments/83406-dnf-fix-arch-cmp.yml new file mode 100644 index 00000000000..c890d662e44 --- /dev/null +++ b/changelogs/fragments/83406-dnf-fix-arch-cmp.yml @@ -0,0 +1,2 @@ +bugfixes: + - dnf - fix an issue where two packages of the same ``evr`` but different arch failed to install (https://github.com/ansible/ansible/issues/83406) diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index 2ab66fbd622..a241d9b9ca8 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -754,7 +754,7 @@ class DnfModule(YumDnf): installed = sorted(self.base.sack.query().installed().filter(name=available.name).run())[-1] except IndexError: return False - return installed > available + return installed.evr_gt(available) and installed.arch == available.arch def _mark_package_install(self, pkg_spec, upgrade=False): """Mark the package for install.""" diff --git a/test/integration/targets/dnf/tasks/repo.yml b/test/integration/targets/dnf/tasks/repo.yml index d50535be1b7..634b46f48ca 100644 --- a/test/integration/targets/dnf/tasks/repo.yml +++ b/test/integration/targets/dnf/tasks/repo.yml @@ -542,3 +542,23 @@ dnf: name: provides_foo* state: absent + +- name: test that only evr is compared, avoiding a situation when a specific arch would be considered as a "newer" package + block: + - dnf: + name: "{{ item }}" + state: present + loop: + - "dinginessentail-1.0-1.x86_64" + - "dinginessentail-1.0-1.i686" + register: dnf_results + + - assert: + that: + - dnf_results["results"][0] is changed + - dnf_results["results"][1] is changed + always: + - name: Clean up + dnf: + name: dinginessentail + state: absent