From 1a4ae5e9aa51ec9a945924da218b73946b8e1a2a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:09:34 +0200 Subject: [PATCH] [PR #6785/704a3019 backport][stable-6] Handle pkg_info(1) error message "Can't find" (#6892) Handle pkg_info(1) error message "Can't find" (#6785) * Handle pkg_info(1) error message "Can't find" * Update plugins/modules/openbsd_pkg.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 704a3019b74bafa9ebae6770bbf75e685a27a40d) Co-authored-by: Rafael Sadowski --- changelogs/fragments/6785-openbsd_pkg_pkg_info_handling.yml | 2 ++ plugins/modules/openbsd_pkg.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/6785-openbsd_pkg_pkg_info_handling.yml diff --git a/changelogs/fragments/6785-openbsd_pkg_pkg_info_handling.yml b/changelogs/fragments/6785-openbsd_pkg_pkg_info_handling.yml new file mode 100644 index 0000000000..081411a602 --- /dev/null +++ b/changelogs/fragments/6785-openbsd_pkg_pkg_info_handling.yml @@ -0,0 +1,2 @@ +bugfixes: + - openbsd_pkg - the pkg_info(1) behavior has changed in OpenBSD >7.3. The error message ``Can't find`` should not lead to an error case (https://github.com/ansible-collections/community.general/pull/6785). diff --git a/plugins/modules/openbsd_pkg.py b/plugins/modules/openbsd_pkg.py index 2baea828ab..a739d47829 100644 --- a/plugins/modules/openbsd_pkg.py +++ b/plugins/modules/openbsd_pkg.py @@ -169,7 +169,11 @@ def get_package_state(names, pkg_spec, module): rc, stdout, stderr = execute_command(command, module) if stderr: - module.fail_json(msg="failed in get_package_state(): " + stderr) + match = re.search(r"^Can't find inst:%s$" % re.escape(name), stderr) + if match: + pkg_spec[name]['installed_state'] = False + else: + module.fail_json(msg="failed in get_package_state(): " + stderr) if stdout: # If the requested package name is just a stem, like "python", we may