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
This commit is contained in:
Patrik Lundin 2013-07-09 20:56:22 +02:00
parent cff4ab511c
commit a67ea75dec

View file

@ -102,7 +102,7 @@ def get_package_state(name, specific_version):
return False return False
# Function used to make sure a package is present. # 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: if module.check_mode:
install_cmd = 'pkg_add -In' install_cmd = 'pkg_add -In'
else: else:
@ -113,16 +113,28 @@ def package_present(name, installed_state, module):
# Attempt to install the package # Attempt to install the package
(rc, stdout, stderr) = execute_command("%s %s" % (install_cmd, name), syslogging) (rc, stdout, stderr) = execute_command("%s %s" % (install_cmd, name), syslogging)
# pkg_add returns 0 even if the package does not exist # The behaviour of pkg_add is a bit different depending on if a
# so depend on stderr instead if something bad happened. # specific version is supplied or not.
if stderr: #
rc = 1 # When a specific version is supplied the return code will be 0 when
changed=False # 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: else:
# Depend on stderr instead and fake the return code.
if stderr:
rc = 1
changed=False
if rc == 0:
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=True)
changed=True changed=True
else: else:
rc = 0 rc = 0
stdout = '' stdout = ''
@ -234,7 +246,7 @@ def main():
# Perform requested action # Perform requested action
if state in ['installed', 'present']: 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']: elif state in ['absent', 'removed']:
(rc, stdout, stderr, changed) = package_absent(name, installed_state, module) (rc, stdout, stderr, changed) = package_absent(name, installed_state, module)
elif state == 'latest': elif state == 'latest':