summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorRodolfo Carvalho <rhcarvalho@gmail.com>2017-08-03 10:52:51 +0200
committerRodolfo Carvalho <rhcarvalho@gmail.com>2017-08-24 15:00:25 +0200
commit6ba5603ea8ef2664210970f7c7901b86ebe984f8 (patch)
tree48a00d120c7f283af990ecca9e71d6aeb15a7240 /roles
parent80476c7dea2b3f6f42ebce5a7947af1d3b9dbedb (diff)
downloadopenshift-6ba5603ea8ef2664210970f7c7901b86ebe984f8.tar.gz
openshift-6ba5603ea8ef2664210970f7c7901b86ebe984f8.tar.bz2
openshift-6ba5603ea8ef2664210970f7c7901b86ebe984f8.tar.xz
openshift-6ba5603ea8ef2664210970f7c7901b86ebe984f8.zip
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.
Diffstat (limited to 'roles')
-rw-r--r--roles/openshift_health_checker/callback_plugins/zz_failure_summary.py13
1 files changed, 11 insertions, 2 deletions
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):