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 0000000000..3a496e2869 --- /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 3961a78aab..6c8e7ce499 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))