1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

upgrade should obey check mode

This commit is contained in:
Lorin Hochstein 2013-03-31 21:48:08 -04:00
parent 614642f8e9
commit 9289db18b4

View file

@ -187,16 +187,20 @@ def remove(m, pkgspec, cache, purge=False):
m.exit_json(changed=True)
def upgrade(m, mode="yes"):
if m.check_mode:
check_arg = '--simulate'
else:
check_arg = ''
upgrade_command = 'upgrade'
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)
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)
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)
if rc:
m.fail_json(msg="'aptitude safe-upgrade' failed: %s" % err)