From 6ba5603ea8ef2664210970f7c7901b86ebe984f8 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Thu, 3 Aug 2017 10:52:51 +0200 Subject: Handle exceptions in failure summary cb plugin This serves two purposes: - Gracefully omit the summary if there was an error computing it, no confusion to the regular end user. - Provide a stacktrace of the error when running verbose, giving developers or users reporting bugs a better insight of what went wrong, as opposed to Ansible's opaque handling of errors in callback plugins. --- .../callback_plugins/zz_failure_summary.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'roles') diff --git a/roles/openshift_health_checker/callback_plugins/zz_failure_summary.py b/roles/openshift_health_checker/callback_plugins/zz_failure_summary.py index 46cc3b577..349655966 100644 --- a/roles/openshift_health_checker/callback_plugins/zz_failure_summary.py +++ b/roles/openshift_health_checker/callback_plugins/zz_failure_summary.py @@ -5,6 +5,7 @@ by Ansible, thus making its output the last thing that users see. """ from collections import defaultdict +import traceback from ansible.plugins.callback import CallbackBase from ansible import constants as C @@ -40,8 +41,16 @@ class CallbackModule(CallbackBase): def v2_playbook_on_stats(self, stats): super(CallbackModule, self).v2_playbook_on_stats(stats) - if self.__failures: - self._display.display(failure_summary(self.__failures, self.__playbook_file)) + # pylint: disable=broad-except; capturing exceptions broadly is + # intentional, to isolate arbitrary failures in this callback plugin. + try: + if self.__failures: + self._display.display(failure_summary(self.__failures, self.__playbook_file)) + except Exception: + msg = stringc( + u'An error happened while generating a summary of failures:\n' + u'{}'.format(traceback.format_exc()), C.COLOR_WARN) + self._display.v(msg) def failure_summary(failures, playbook): -- cgit v1.2.3