Added apt-get upgrade and dist-upgrade option

reviewable/pr18780/r1
Remy 12 years ago
parent 34fe59c6a4
commit 03254282c7

29
apt

@ -67,6 +67,12 @@ options:
required: false required: false
default: "no" default: "no"
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
upgrade:
description:
- If yes, performs an apt-get upgrade. If dist, performs an apt-get dist-upgrade.
required: false
default: no
choices: [ "yes", "no", "dist"]
author: Matthew Williams author: Matthew Williams
notes: [] notes: []
examples: examples:
@ -82,6 +88,8 @@ examples:
description: Update the repository cache and update package C(ngnix) to latest version using default release C(squeeze-backport) description: Update the repository cache and update package C(ngnix) to latest version using default release C(squeeze-backport)
- code: "apt: pkg=openjdk-6-jdk state=latest install_recommends=no" - code: "apt: pkg=openjdk-6-jdk state=latest install_recommends=no"
description: Install latest version of C(openjdk-6-jdk) ignoring C(install-reccomends) description: Install latest version of C(openjdk-6-jdk) ignoring C(install-reccomends)
- code: "apt: upgrade=dist"
description: Update all packages to the latest version
''' '''
import traceback import traceback
@ -164,6 +172,17 @@ def remove(m, pkgspec, cache, purge=False):
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err)) m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err))
m.exit_json(changed=True) m.exit_json(changed=True)
def upgrade(m, mode="yes"):
upgrade_command = "upgrade"
if mode == "dist":
upgrade_command = "dist-upgrade"
cmd = "%s -q -y %s" % (APT, upgrade_command)
rc, out, err = m.run_command(cmd)
if rc:
m.fail_json(msg="'apt-get %s ' failed: %s" % (upgrade_command, err))
if "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." in out :
m.exit_json(changed=False)
m.exit_json(changed=True)
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
@ -174,7 +193,8 @@ def main():
package = dict(default=None, aliases=['pkg', 'name']), package = dict(default=None, aliases=['pkg', 'name']),
default_release = dict(default=None, aliases=['default-release']), default_release = dict(default=None, aliases=['default-release']),
install_recommends = dict(default='yes', aliases=['install-recommends'], choices=['yes', 'no']), install_recommends = dict(default='yes', aliases=['install-recommends'], choices=['yes', 'no']),
force = dict(default='no', choices=['yes', 'no']) force = dict(default='no', choices=['yes', 'no']),
upgrade = dict(default="no", choices=['yes', 'no', 'dist'])
) )
) )
@ -188,8 +208,8 @@ def main():
module.fail_json(msg="Cannot find apt-get") module.fail_json(msg="Cannot find apt-get")
p = module.params p = module.params
if p['package'] is None and p['update_cache'] != 'yes': if p['package'] is None and p['update_cache'] != 'yes' and p['upgrade'] == 'no':
module.fail_json(msg='pkg=name and/or update_cache=yes is required') module.fail_json(msg='pkg=name and/or update_cache=yes or upgrade=yes is required')
install_recommends = module.boolean(p['install_recommends']) install_recommends = module.boolean(p['install_recommends'])
@ -207,6 +227,9 @@ def main():
force_yes = module.boolean(p['force']) force_yes = module.boolean(p['force'])
if p['upgrade'] != 'no' and p['package'] is None:
upgrade(module, p['upgrade'])
packages = p['package'].split(',') packages = p['package'].split(',')
latest = p['state'] == 'latest' latest = p['state'] == 'latest'
for package in packages: for package in packages:

Loading…
Cancel
Save