mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07: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:
parent
e39fbb9db4
commit
31ccb3c29d
3 changed files with 9 additions and 1 deletions
2
changelogs/fragments/diff_yaml.yml
Normal file
2
changelogs/fragments/diff_yaml.yml
Normal file
|
@ -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)
|
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):
|
def _get_diff(self, difflist):
|
||||||
|
|
||||||
if not isinstance(difflist, list):
|
if not isinstance(difflist, list):
|
||||||
|
@ -166,7 +169,7 @@ class CallbackBase(AnsiblePlugin):
|
||||||
# format complex structures into 'files'
|
# format complex structures into 'files'
|
||||||
for x in ['before', 'after']:
|
for x in ['before', 'after']:
|
||||||
if isinstance(diff[x], MutableMapping):
|
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:
|
if 'before_header' in diff:
|
||||||
before_header = u"before: %s" % diff['before_header']
|
before_header = u"before: %s" % diff['before_header']
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -125,3 +125,6 @@ class CallbackModule(Default):
|
||||||
# indent by a couple of spaces
|
# indent by a couple of spaces
|
||||||
dumped = '\n '.join(dumped.split('\n')).rstrip()
|
dumped = '\n '.join(dumped.split('\n')).rstrip()
|
||||||
return dumped
|
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…
Add table
Add a link
Reference in a new issue