From c97f2b4c017874795191ab9ae69389770f8b54e5 Mon Sep 17 00:00:00 2001 From: David Baumann Date: Mon, 1 Oct 2018 18:06:14 +0200 Subject: [PATCH] Fix callout json plugin show global stats (#43123) * fix callback Plugin json to support global stat set by set_stats module * refactor to not break compatiblity, add trailing comma on output dict * Remove sorted, as it not needed * refactor, to sivels better code * clean some code messup * add changelog fragment * added missing new line * fix pep8 stuff --- .../fragments/43123-add_support_for_per_host_no_stats.yaml | 3 +++ lib/ansible/plugins/callback/json.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/43123-add_support_for_per_host_no_stats.yaml diff --git a/changelogs/fragments/43123-add_support_for_per_host_no_stats.yaml b/changelogs/fragments/43123-add_support_for_per_host_no_stats.yaml new file mode 100644 index 00000000000..3a496e28697 --- /dev/null +++ b/changelogs/fragments/43123-add_support_for_per_host_no_stats.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Add support for per_host:no stats for the callback plugin **json** (https://github.com/ansible/ansible/pull/43123) diff --git a/lib/ansible/plugins/callback/json.py b/lib/ansible/plugins/callback/json.py index 3961a78aab9..6c8e7ce4996 100644 --- a/lib/ansible/plugins/callback/json.py +++ b/lib/ansible/plugins/callback/json.py @@ -101,14 +101,17 @@ class CallbackModule(CallbackBase): summary[h] = s custom_stats = {} + global_custom_stats = {} + if self.get_option('show_custom_stats') and stats.custom: custom_stats.update(dict((self._convert_host_to_name(k), v) for k, v in stats.custom.items())) - custom_stats.pop('_run', None) + global_custom_stats.update(custom_stats.pop('_run', {})) output = { 'plays': self.results, 'stats': summary, 'custom_stats': custom_stats, + 'global_custom_stats': global_custom_stats, } self._display.display(json.dumps(output, indent=4, sort_keys=True))