From 704a3019b74bafa9ebae6770bbf75e685a27a40d Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Sat, 8 Jul 2023 10:12:42 +0200 Subject: [PATCH] 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 --- 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 0f3376aa88..c831136110 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