Use aptitude safe-upgrade instead of apt-get upgrade to implement
apt: upgrade=yes. Using aptitude ensures that missing dependencies
will also be installed.
Fixes #2540
... | ... |
@@ -69,7 +69,7 @@ options: |
69 | 69 |
choices: [ "yes", "no" ] |
70 | 70 |
upgrade: |
71 | 71 |
description: |
72 |
- - '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.' |
|
72 |
+ - 'If yes, performs an aptitude safe-upgrade. If dist, performs an apt-get dist-upgrade. Note: This does not upgrade a specific package, use state=latest for that.' |
|
73 | 73 |
version_added: "1.1" |
74 | 74 |
required: false |
75 | 75 |
default: no |
... | ... |
@@ -91,6 +91,7 @@ examples: |
91 | 91 |
description: Install latest version of C(openjdk-6-jdk) ignoring C(install-reccomends) |
92 | 92 |
- code: "apt: upgrade=dist" |
93 | 93 |
description: Update all packages to the latest version |
94 |
+requirements: [ python-apt, aptitude ] |
|
94 | 95 |
''' |
95 | 96 |
|
96 | 97 |
import traceback |
... | ... |
@@ -188,13 +189,19 @@ def remove(m, pkgspec, cache, purge=False): |
188 | 188 |
def upgrade(m, mode="yes"): |
189 | 189 |
upgrade_command = 'upgrade' |
190 | 190 |
if mode == "dist": |
191 |
- upgrade_command = 'dist-upgrade' |
|
192 |
- cmd = '%s -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" %s' % (APT, upgrade_command) |
|
193 |
- rc, out, err = m.run_command(cmd) |
|
194 |
- if rc: |
|
195 |
- m.fail_json(msg="'apt-get %s' failed: %s" % (upgrade_command, err)) |
|
196 |
- if "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." in out : |
|
197 |
- m.exit_json(changed=False) |
|
191 |
+ cmd = '%s -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade' % APT |
|
192 |
+ rc, out, err = m.run_command(cmd) |
|
193 |
+ if rc: |
|
194 |
+ m.fail_json(msg="'apt-get %s' failed: %s" % (upgrade_command, err)) |
|
195 |
+ if "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." in out : |
|
196 |
+ m.exit_json(changed=False) |
|
197 |
+ else: |
|
198 |
+ cmd = "/usr/bin/aptitude safe-upgrade -y" |
|
199 |
+ rc, out, err = m.run_command(cmd) |
|
200 |
+ if rc: |
|
201 |
+ m.fail_json(msg="'aptitude safe-upgrade' failed: %s" % err) |
|
202 |
+ if "No packages will be installed, upgraded, or removed." in out: |
|
203 |
+ m.exit_json(changed=False) |
|
198 | 204 |
m.exit_json(changed=True) |
199 | 205 |
|
200 | 206 |
def main(): |