From bbe231e2612a081c8c8489ba4c0c5554f2e06bda Mon Sep 17 00:00:00 2001 From: tover99 <101673769+tover99@users.noreply.github.com> Date: Tue, 5 Apr 2022 05:43:53 +0200 Subject: [PATCH] Bugfix: zypper issue with specified package versions (#4421) * fixed issue with specified package versions zypper.py was doing nothing on state=present, when ALL requestet/checked packages had a specific version stated. This was caused by get_installed_state() being called with an empty package list, which in this case returns information about all ALL installed packages. This lead to an exessive filter list prerun_state, essentially removing all packages that are installed in ANY version on the target system from the request list. * Create 4421-zypper_package_version_handling_fix added changelog fragment for https://github.com/ansible-collections/community.general/pull/4421 * Delete 4421-zypper_package_version_handling_fix * Create 4421-zypper_package_version_handling_fix.yml --- .../fragments/4421-zypper_package_version_handling_fix.yml | 2 ++ plugins/modules/packaging/os/zypper.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/4421-zypper_package_version_handling_fix.yml diff --git a/changelogs/fragments/4421-zypper_package_version_handling_fix.yml b/changelogs/fragments/4421-zypper_package_version_handling_fix.yml new file mode 100644 index 0000000000..eacdf84beb --- /dev/null +++ b/changelogs/fragments/4421-zypper_package_version_handling_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - zypper - fixed bug that caused zypper to always report [ok] and do nothing on ``state=present`` when all packages in ``name`` had a version specification (https://github.com/ansible-collections/community.general/issues/4371, https://github.com/ansible-collections/community.general/pull/4421). diff --git a/plugins/modules/packaging/os/zypper.py b/plugins/modules/packaging/os/zypper.py index 43bba6404c..ab49051b17 100644 --- a/plugins/modules/packaging/os/zypper.py +++ b/plugins/modules/packaging/os/zypper.py @@ -427,7 +427,9 @@ def package_present(m, name, want_latest): # if a version is given leave the package in to let zypper handle the version # resolution packageswithoutversion = [p for p in packages if not p.version] - prerun_state = get_installed_state(m, packageswithoutversion) + prerun_state = {} + if packageswithoutversion: + prerun_state = get_installed_state(m, packageswithoutversion) # generate lists of packages to install or remove packages = [p for p in packages if p.shouldinstall != (p.name in prerun_state)]