|
|
|
@ -67,6 +67,12 @@ 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.
|
|
|
|
|
required: false
|
|
|
|
|
default: no
|
|
|
|
|
choices: [ "yes", "no", "dist"]
|
|
|
|
|
author: Matthew Williams
|
|
|
|
|
notes: []
|
|
|
|
|
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)
|
|
|
|
|
- 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
|
|
|
|
@ -164,6 +172,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 = "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():
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
@ -174,7 +193,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'], 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")
|
|
|
|
|
|
|
|
|
|
p = module.params
|
|
|
|
|
if p['package'] is None and p['update_cache'] != 'yes':
|
|
|
|
|
module.fail_json(msg='pkg=name and/or update_cache=yes is required')
|
|
|
|
|
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 or upgrade=yes is required')
|
|
|
|
|
|
|
|
|
|
install_recommends = module.boolean(p['install_recommends'])
|
|
|
|
|
|
|
|
|
@ -207,6 +227,9 @@ def main():
|
|
|
|
|
|
|
|
|
|
force_yes = module.boolean(p['force'])
|
|
|
|
|
|
|
|
|
|
if p['upgrade'] != 'no' and p['package'] is None:
|
|
|
|
|
upgrade(module, p['upgrade'])
|
|
|
|
|
|
|
|
|
|
packages = p['package'].split(',')
|
|
|
|
|
latest = p['state'] == 'latest'
|
|
|
|
|
for package in packages:
|
|
|
|
|