Diff mode returns yaml diffs in yaml callback plugin (#48794)

* Diff mode returns yaml diffs in yaml callback plugin

* Add changelog for yaml diff mode
pull/49035/head
Will Thames 6 years ago committed by John R Barker
parent e39fbb9db4
commit 31ccb3c29d

@ -0,0 +1,2 @@
minor_changes:
- diff mode outputs in YAML form when used with yaml callback plugin

@ -147,6 +147,9 @@ class CallbackBase(AnsiblePlugin):
self._display.display(msg, color=C.COLOR_ERROR, stderr=use_stderr)
def _serialize_diff(self, diff):
return json.dumps(diff, sort_keys=True, indent=4, separators=(u',', u': ')) + u'\n'
def _get_diff(self, difflist):
if not isinstance(difflist, list):
@ -166,7 +169,7 @@ class CallbackBase(AnsiblePlugin):
# format complex structures into 'files'
for x in ['before', 'after']:
if isinstance(diff[x], MutableMapping):
diff[x] = json.dumps(diff[x], sort_keys=True, indent=4, separators=(u',', u': ')) + u'\n'
diff[x] = self._serialize_diff(diff[x])
if 'before_header' in diff:
before_header = u"before: %s" % diff['before_header']
else:

@ -125,3 +125,6 @@ class CallbackModule(Default):
# indent by a couple of spaces
dumped = '\n '.join(dumped.split('\n')).rstrip()
return dumped
def _serialize_diff(self, diff):
return to_text(yaml.dump(diff, allow_unicode=True, width=1000, Dumper=AnsibleDumper, default_flow_style=False))

Loading…
Cancel
Save