yum always return changes dict, not only in check mode (#51987)

Previously the yum module would provide a `changes` dict when
executed in check mode but omit it when not in check mode in favor
of the `results` data which is raw output from the yum command. This
pull request makes that output uniform.

Fixes #51724

Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
Adam Miller 2019-02-13 16:46:32 -06:00 committed by ansibot
parent 9e71ec71a3
commit ea0e2bf2b3
4 changed files with 97 additions and 29 deletions

View file

@ -808,6 +808,8 @@ class YumModule(YumDnf):
if self.module.check_mode:
self.module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
else:
res['changes'] = dict(installed=pkgs)
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
rc, out, err = self.module.run_command(cmd, environ_update=lang_env)
@ -1043,6 +1045,8 @@ class YumModule(YumDnf):
if pkgs:
if self.module.check_mode:
self.module.exit_json(changed=True, results=res['results'], changes=dict(removed=pkgs))
else:
res['changes'] = dict(removed=pkgs)
# run an actual yum transaction
if self.autoremove:
@ -1273,38 +1277,38 @@ class YumModule(YumDnf):
self.module.fail_json(**res)
# check_mode output
if self.module.check_mode:
to_update = []
for w in will_update:
if w.startswith('@'):
to_update.append((w, None))
elif w not in updates:
other_pkg = will_update_from_other_package[w]
to_update.append(
(
w,
'because of (at least) %s-%s.%s from %s' % (
other_pkg,
updates[other_pkg]['version'],
updates[other_pkg]['dist'],
updates[other_pkg]['repo']
)
to_update = []
for w in will_update:
if w.startswith('@'):
to_update.append((w, None))
elif w not in updates:
other_pkg = will_update_from_other_package[w]
to_update.append(
(
w,
'because of (at least) %s-%s.%s from %s' % (
other_pkg,
updates[other_pkg]['version'],
updates[other_pkg]['dist'],
updates[other_pkg]['repo']
)
)
else:
to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo'])))
if self.update_only:
res['changes'] = dict(installed=[], updated=to_update)
)
else:
res['changes'] = dict(installed=pkgs['install'], updated=to_update)
to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo'])))
if self.update_only:
res['changes'] = dict(installed=[], updated=to_update)
else:
res['changes'] = dict(installed=pkgs['install'], updated=to_update)
if obsoletes:
res['obsoletes'] = obsoletes
# return results before we actually execute stuff
if self.module.check_mode:
if will_update or pkgs['install']:
res['changed'] = True
if obsoletes:
res['obsoletes'] = obsoletes
return res
# run commands
@ -1340,9 +1344,6 @@ class YumModule(YumDnf):
if rc:
res['failed'] = True
if obsoletes:
res['obsoletes'] = obsoletes
return res
def ensure(self, repoq):