From 737090dd139edbce0a7e90d4ba136bdc19dd6346 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 6 Jan 2016 10:29:35 -0500 Subject: [PATCH] now show full callback stacktrace when vvv+ Still is a warning as we don't want to repeat it multiple times nor additional callbacks to stop ansible execution. hopefully we can avoid shipping w/o exceptions in the default/minimal callbacks... Also added feature that now allows for 'preformated' strings passed to warning --- lib/ansible/executor/task_queue_manager.py | 7 ++++++- lib/ansible/utils/display.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index dae70a1292..ab46d6f78b 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -290,8 +290,13 @@ class TaskQueueManager: try: method(*args, **kwargs) except Exception as e: + import traceback + orig_tb = traceback.format_exc() try: v1_method = method.replace('v2_','') v1_method(*args, **kwargs) except Exception: - display.warning('Error when using %s: %s' % (method, str(e))) + if display.verbosity >= 3: + display.warning(orig_tb, formatted=True) + else: + display.warning('Error when using %s: %s' % (method, str(e))) diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 8700a51018..ef1ac57b04 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -202,10 +202,15 @@ class Display: self.display(new_msg.strip(), color=C.COLOR_DEPRECATE, stderr=True) self._deprecations[new_msg] = 1 - def warning(self, msg): - new_msg = "\n[WARNING]: %s" % msg - wrapped = textwrap.wrap(new_msg, self.columns) - new_msg = "\n".join(wrapped) + "\n" + def warning(self, msg, formatted=False): + + if not formatted: + new_msg = "\n[WARNING]: %s" % msg + wrapped = textwrap.wrap(new_msg, self.columns) + new_msg = "\n".join(wrapped) + "\n" + else: + new_msg = "\n[WARNING]: \n%s" % msg + if new_msg not in self._warns: self.display(new_msg, color=C.COLOR_WARN, stderr=True) self._warns[new_msg] = 1