From a67ea75decb3bccd09b61bbf7ab720f56ebd687a Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Tue, 9 Jul 2013 20:56:22 +0200 Subject: [PATCH] openbsd_pkg: handle pkg_add quirks better. This fixes a problem when trying to install a package with a specific version number from a local directory and the local directory is checked after a remote repository: Error from http://ftp.eu.openbsd.org/pub/OpenBSD/[...]/packagename-1.0.tgz ftp: Error retrieving file: 404 Not Found packagename-1.0: ok --- library/packaging/openbsd_pkg | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/library/packaging/openbsd_pkg b/library/packaging/openbsd_pkg index c4ac57d8a25..16892283a70 100644 --- a/library/packaging/openbsd_pkg +++ b/library/packaging/openbsd_pkg @@ -102,7 +102,7 @@ def get_package_state(name, specific_version): return False # Function used to make sure a package is present. -def package_present(name, installed_state, module): +def package_present(name, installed_state, specific_version, module): if module.check_mode: install_cmd = 'pkg_add -In' else: @@ -113,16 +113,28 @@ def package_present(name, installed_state, module): # Attempt to install the package (rc, stdout, stderr) = execute_command("%s %s" % (install_cmd, name), syslogging) - # pkg_add returns 0 even if the package does not exist - # so depend on stderr instead if something bad happened. - if stderr: - rc = 1 - changed=False + # The behaviour of pkg_add is a bit different depending on if a + # specific version is supplied or not. + # + # When a specific version is supplied the return code will be 0 when + # a package is found and 1 when it is not, if a version is not + # supplied the tool will exit 0 in both cases: + if specific_version: + # Depend on the return code. + if rc: + changed=False else: + # Depend on stderr instead and fake the return code. + if stderr: + rc = 1 + changed=False + + if rc == 0: if module.check_mode: module.exit_json(changed=True) changed=True + else: rc = 0 stdout = '' @@ -234,7 +246,7 @@ def main(): # Perform requested action if state in ['installed', 'present']: - (rc, stdout, stderr, changed) = package_present(name, installed_state, module) + (rc, stdout, stderr, changed) = package_present(name, installed_state, specific_version, module) elif state in ['absent', 'removed']: (rc, stdout, stderr, changed) = package_absent(name, installed_state, module) elif state == 'latest':