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 00000000000..eacdf84beb7 --- /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 2295b5a566f..1c6bc908f7d 100644 --- a/plugins/modules/packaging/os/zypper.py +++ b/plugins/modules/packaging/os/zypper.py @@ -417,7 +417,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)]