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

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
This commit is contained in:
Will Thames 2018-11-23 04:03:25 +10:00 committed by John R Barker
parent e39fbb9db4
commit 31ccb3c29d
3 changed files with 9 additions and 1 deletions

View file

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

View file

@ -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:

View file

@ -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))