Refactor openbsd package upgrade change to work more like yum/apt

pull/18777/head
James Cammarata 11 years ago committed by Matt Clay
parent 6aaf5eb1d6
commit e7405643e1

@ -60,8 +60,8 @@ EXAMPLES = '''
# Specify the default flavour to avoid ambiguity errors # Specify the default flavour to avoid ambiguity errors
- openbsd_pkg: name=vim-- state=present - openbsd_pkg: name=vim-- state=present
# Make sure all packages are upgraded # Update all packages on the system
- openbsd_pkg: upgrade=yes - openbsd_pkg: name=* state=latest
''' '''
# Control if we write debug information to syslog. # Control if we write debug information to syslog.
@ -336,15 +336,9 @@ def upgrade_packages(module):
# Try to find any occurance of a package changing version like: # Try to find any occurance of a package changing version like:
# "bzip2-1.0.6->1.0.6p0: ok". # "bzip2-1.0.6->1.0.6p0: ok".
match = re.search("\W\w.+->.+: ok\W", stdout) changed = re.search("\W\w.+->.+: ok\W", stdout)
if match:
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=changed)
changed=True
else:
changed=False
# It seems we can not trust the return value, so depend on the presence of # It seems we can not trust the return value, so depend on the presence of
# stderr to know if something failed. # stderr to know if something failed.
@ -363,16 +357,12 @@ def main():
argument_spec = dict( argument_spec = dict(
name = dict(), name = dict(),
state = dict(choices=['absent', 'installed', 'latest', 'present', 'removed']), state = dict(choices=['absent', 'installed', 'latest', 'present', 'removed']),
upgrade = dict(choices=['yes']),
), ),
mutually_exclusive = [['name', 'upgrade']],
required_one_of = [['name', 'upgrade']],
supports_check_mode = True supports_check_mode = True
) )
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
upgrade = module.params['upgrade']
rc = 0 rc = 0
stdout = '' stdout = ''
@ -380,12 +370,18 @@ def main():
result = {} result = {}
result['name'] = name result['name'] = name
result['state'] = state result['state'] = state
result['upgrade'] = upgrade
if name: if name:
if not state: if not state:
module.fail_json(msg="missing required arguments: state") module.fail_json(msg="missing required arguments: state")
if name == '*':
if state != 'latest':
module.fail_json(msg="the package name '*' is only valid when using state=latest")
else:
# Perform an upgrade of all installed packages.
(rc, stdout, stderr, changed) = upgrade_packages(module)
else:
# Parse package name and put results in the pkg_spec dictionary. # Parse package name and put results in the pkg_spec dictionary.
pkg_spec = {} pkg_spec = {}
parse_package_name(name, pkg_spec, module) parse_package_name(name, pkg_spec, module)
@ -400,9 +396,6 @@ def main():
(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':
(rc, stdout, stderr, changed) = package_latest(name, installed_state, pkg_spec, module) (rc, stdout, stderr, changed) = package_latest(name, installed_state, pkg_spec, module)
elif upgrade:
# Perform an upgrade of all installed packages.
(rc, stdout, stderr, changed) = upgrade_packages(module)
else: else:
module.fail_json(msg="Something is broken, you should never end up here") module.fail_json(msg="Something is broken, you should never end up here")

Loading…
Cancel
Save