From 896dec44a684eb222b52918a9ac82eb0aa42a155 Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Sat, 15 Oct 2016 09:01:48 +0200 Subject: [PATCH] openbsd_pkg: Use correct part of name in match. (#3151) * openbsd_pkg: Use correct part of name in match. Previously this part of the code could assume that the name was a stem with nothing else attached (like "autoconf"). With the introduction of the branch syntax ("autoconf%2.13") this is no longer true. Check if the package name was identified as using a "branch" style name, and base the match on the leading part of the name if that is the case. While here remove unnecessary "pass" and tidy up debug log message. Problem reported by @jasperla. * openbsd_pkg: Add missing "." in comment. --- .../modules/extras/packaging/os/openbsd_pkg.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py b/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py index 59fdd35c26b..67583cdf36e 100644 --- a/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py +++ b/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py @@ -176,11 +176,14 @@ def package_present(name, installed_state, pkg_spec, module): # "file:/local/package/directory/ is empty" message on stderr # while still installing the package, so we need to look for # for a message like "packagename-1.0: ok" just in case. - match = re.search("\W%s-[^:]+: ok\W" % name, stdout) + if pkg_spec['style'] == 'branch': + match = re.search("\W%s-[^:]+: ok\W" % pkg_spec['pkgname'], stdout) + else: + match = re.search("\W%s-[^:]+: ok\W" % name, stdout) + if match: # It turns out we were able to install the package. - module.debug("package_present(): we were able to install package") - pass + module.debug("package_present(): we were able to install the package") else: # We really did fail, fake the return code. module.debug("package_present(): we really did fail") @@ -353,6 +356,10 @@ def parse_package_name(name, pkg_spec, module): pkg_spec['style'] = 'branch' + # Key names from description in pkg_add(1). + pkg_spec['pkgname'] = pkg_spec['stem'].split('%')[0] + pkg_spec['branch'] = pkg_spec['stem'].split('%')[1] + # Sanity check that there are no trailing dashes in flavor. # Try to stop strange stuff early so we can be strict later. if pkg_spec['flavor']: