upgrade should obey check mode

This commit is contained in:
Lorin Hochstein 2013-03-31 21:48:08 -04:00
parent 75a9687a2a
commit 3eb859a01c

8
apt
View file

@ -187,16 +187,20 @@ def remove(m, pkgspec, cache, purge=False):
m.exit_json(changed=True) m.exit_json(changed=True)
def upgrade(m, mode="yes"): def upgrade(m, mode="yes"):
if m.check_mode:
check_arg = '--simulate'
else:
check_arg = ''
upgrade_command = 'upgrade' upgrade_command = 'upgrade'
if mode == "dist": if mode == "dist":
cmd = '%s -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade' % APT cmd = '%s %s -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade' % (APT, check_arg)
rc, out, err = m.run_command(cmd) rc, out, err = m.run_command(cmd)
if rc: if rc:
m.fail_json(msg="'apt-get %s' failed: %s" % (upgrade_command, err)) 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 : if "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." in out :
m.exit_json(changed=False) m.exit_json(changed=False)
else: else:
cmd = "/usr/bin/aptitude safe-upgrade -y" cmd = "/usr/bin/aptitude safe-upgrade %s -y" % check_arg
rc, out, err = m.run_command(cmd) rc, out, err = m.run_command(cmd)
if rc: if rc:
m.fail_json(msg="'aptitude safe-upgrade' failed: %s" % err) m.fail_json(msg="'aptitude safe-upgrade' failed: %s" % err)