From 31db1e31d48402782a7a79b39397ebec66b99074 Mon Sep 17 00:00:00 2001 From: Remy Date: Sun, 3 Feb 2013 10:46:23 +0100 Subject: [PATCH 1/6] Added apt-get upgrade and dist-upgrade option --- library/apt | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/library/apt b/library/apt index ee1c974f337..8180776423f 100644 --- a/library/apt +++ b/library/apt @@ -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: From fd59a03193231aa7fe2030269d26e043352bca95 Mon Sep 17 00:00:00 2001 From: Remy Date: Sun, 3 Feb 2013 19:14:37 +0100 Subject: [PATCH 2/6] Added version flag (1.1) to updated apt module. --- library/apt | 1 + 1 file changed, 1 insertion(+) diff --git a/library/apt b/library/apt index 8180776423f..39f5f8b99f2 100644 --- a/library/apt +++ b/library/apt @@ -70,6 +70,7 @@ options: upgrade: description: - If yes, performs an apt-get upgrade. If dist, performs an apt-get dist-upgrade. + version_added: "1.1" required: false default: no choices: [ "yes", "no", "dist"] From 26310f411c15fc13bb1c3febb90f3611e12383b2 Mon Sep 17 00:00:00 2001 From: Remy Date: Mon, 4 Feb 2013 08:44:35 +0100 Subject: [PATCH 3/6] Added check so that upgrade cannot be used with other options. --- library/apt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/apt b/library/apt index 39f5f8b99f2..97358615fdb 100644 --- a/library/apt +++ b/library/apt @@ -69,7 +69,7 @@ options: choices: [ "yes", "no" ] upgrade: description: - - If yes, performs an apt-get upgrade. If dist, performs an apt-get dist-upgrade. + - 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 @@ -230,6 +230,8 @@ def main(): 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' From ad7807fce498aa93b901574b0e33fd3fb4c7e494 Mon Sep 17 00:00:00 2001 From: Remy Date: Thu, 7 Feb 2013 08:00:02 +0100 Subject: [PATCH 4/6] Added DPKG options which lardcanoe suggested --- library/apt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/apt b/library/apt index 97358615fdb..bf96cc4069a 100644 --- a/library/apt +++ b/library/apt @@ -174,9 +174,9 @@ def remove(m, pkgspec, cache, purge=False): m.exit_json(changed=True) def upgrade(m, mode="yes"): - upgrade_command = "upgrade" + upgrade_command = '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade' if mode == "dist": - upgrade_command = "dist-upgrade" + 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: From 5289fa72b602af34a906476f0adb47a38b50b2cd Mon Sep 17 00:00:00 2001 From: Remy van Elst Date: Thu, 28 Feb 2013 20:47:31 +0100 Subject: [PATCH 5/6] apt upgrade support --- library/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/apt b/library/apt index bf96cc4069a..2c9b18546d3 100644 --- a/library/apt +++ b/library/apt @@ -1,6 +1,6 @@ #!/usr/bin/python -tt # -*- coding: utf-8 -*- - +# # (c) 2012, Flowroute LLC # Written by Matthew Williams # Based on yum module written by Seth Vidal From f094d65fdd0154f5f799f126b7c7c7b2745bb1fd Mon Sep 17 00:00:00 2001 From: Remy van Elst Date: Thu, 28 Feb 2013 20:50:07 +0100 Subject: [PATCH 6/6] apt update --- library/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/apt b/library/apt index 2c9b18546d3..bf96cc4069a 100644 --- a/library/apt +++ b/library/apt @@ -1,6 +1,6 @@ #!/usr/bin/python -tt # -*- coding: utf-8 -*- -# + # (c) 2012, Flowroute LLC # Written by Matthew Williams # Based on yum module written by Seth Vidal