Merge branch 'new_branch_for_apt_squashed' of git://github.com/RaymiiOrg/ansible-1 into devel

Conflicts:
	library/apt
pull/2242/merge
Michael DeHaan 12 years ago
commit 7749b34546

@ -67,6 +67,13 @@ options:
required: false
default: "no"
choices: [ "yes", "no" ]
upgrade:
description:
- If yes, performs an apt-get upgrade. If dist, performs an apt-get dist-upgrade. Note: This does not upgrade a specific package, use state=latest for that.
version_added: "1.1"
required: false
default: no
choices: [ "yes", "no", "dist"]
author: Matthew Williams
notes: []
examples:
@ -82,6 +89,8 @@ examples:
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"
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
@ -176,6 +185,17 @@ def remove(m, pkgspec, cache, purge=False):
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err))
m.exit_json(changed=True)
def upgrade(m, mode="yes"):
upgrade_command = '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade'
if mode == "dist":
upgrade_command = '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" 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():
module = AnsibleModule(
@ -186,7 +206,8 @@ def main():
package = dict(default=None, aliases=['pkg', 'name']),
default_release = dict(default=None, aliases=['default-release']),
install_recommends = dict(default='yes', aliases=['install-recommends'], type='bool'),
force = dict(default='no', type='bool')
force = dict(default='no', type='bool'),
upgrade = dict(default="no", type='bool')
),
supports_check_mode = True
)
@ -201,8 +222,8 @@ def main():
module.fail_json(msg="Cannot find apt-get")
p = module.params
if p['package'] is None and not p['update_cache']:
module.fail_json(msg='pkg=name and/or update_cache=yes is required')
if p['package'] is None and not p['update_cache'] and not p['upgrade']:
module.fail_json(msg='pkg=name and/or update_cache=yes or upgrade=yes is required')
install_recommends = p['install_recommends']
@ -220,6 +241,11 @@ def main():
force_yes = p['force']
if p['upgrade'] != 'no' and p['package'] is None:
upgrade(module, p['upgrade'])
elif p['upgrade'] != 'no' and p['package'] != None:
module.fail_json(msg="Upgrade should not be used in conjunction with other options.")
packages = p['package'].split(',')
latest = p['state'] == 'latest'
for package in packages:

Loading…
Cancel
Save