From 0eef9c1e02dacc4b5e0fe7056374d7fd3b2b968e Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Mon, 26 Jun 2023 10:04:34 +0200 Subject: [PATCH 1/2] Handle pkg_info(1) error message "Can't find" --- 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 00000000000..081411a602d --- /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 0f3376aa886..8cee742ab92 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$" % 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 From 9721ab12bec4a18307598aaaddfc7560875e7bf5 Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Fri, 7 Jul 2023 11:11:03 +0200 Subject: [PATCH 2/2] Update plugins/modules/openbsd_pkg.py Co-authored-by: Felix Fontein --- plugins/modules/openbsd_pkg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/openbsd_pkg.py b/plugins/modules/openbsd_pkg.py index 8cee742ab92..c831136110b 100644 --- a/plugins/modules/openbsd_pkg.py +++ b/plugins/modules/openbsd_pkg.py @@ -169,7 +169,7 @@ def get_package_state(names, pkg_spec, module): rc, stdout, stderr = execute_command(command, module) if stderr: - match = re.search(r"^Can't find inst:%s$" % name, stderr) + match = re.search(r"^Can't find inst:%s$" % re.escape(name), stderr) if match: pkg_spec[name]['installed_state'] = False else: