From 02d0e3d2869c4ceea7c3889fe3c717896f383bda Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 20 Sep 2021 17:19:04 +0000 Subject: [PATCH] openbsd_pkg: Fix KeyError (#3336) If package installation has an error after the package is install (e.g. when running tags), then there will be output on stderr and the fallback regex will match; however, since pkg_add exited non-zero, changed is never added as a key to the dictionary. As a result the code at the end of main that checks if anything has changed raises a KeyError. --- changelogs/fragments/3336-openbsd_pkg-fix-KeyError.yml | 5 +++++ plugins/modules/packaging/os/openbsd_pkg.py | 1 + 2 files changed, 6 insertions(+) create mode 100644 changelogs/fragments/3336-openbsd_pkg-fix-KeyError.yml diff --git a/changelogs/fragments/3336-openbsd_pkg-fix-KeyError.yml b/changelogs/fragments/3336-openbsd_pkg-fix-KeyError.yml new file mode 100644 index 0000000000..7f10c186dd --- /dev/null +++ b/changelogs/fragments/3336-openbsd_pkg-fix-KeyError.yml @@ -0,0 +1,5 @@ +--- +bugfixes: + - openbsd_pkg - fix crash from ``KeyError`` exception when package installs, + but ``pkg_add`` returns with a non-zero exit code + (https://github.com/ansible-collections/community.general/pull/3336). diff --git a/plugins/modules/packaging/os/openbsd_pkg.py b/plugins/modules/packaging/os/openbsd_pkg.py index 05c374cb4e..4299d60ad0 100644 --- a/plugins/modules/packaging/os/openbsd_pkg.py +++ b/plugins/modules/packaging/os/openbsd_pkg.py @@ -246,6 +246,7 @@ def package_present(names, pkg_spec, module): if match: # It turns out we were able to install the package. module.debug("package_present(): we were able to install package for name '%s'" % name) + pkg_spec[name]['changed'] = True else: # We really did fail, fake the return code. module.debug("package_present(): we really did fail for name '%s'" % name)