From 6d50a261c590c61320c4762b5a5f706cb9620ee5 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 7 Jul 2015 14:31:15 -0400 Subject: [PATCH] Allow full exception tracebacks to be displayed with increased verbosity --- bin/ansible | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/ansible b/bin/ansible index d64c069251..3a17861ceb 100755 --- a/bin/ansible +++ b/bin/ansible @@ -34,6 +34,7 @@ except Exception: import os import sys +import traceback from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError from ansible.utils.display import Display @@ -41,9 +42,11 @@ from ansible.utils.display import Display ######################################## ### OUTPUT OF LAST RESORT ### class LastResort(object): - def error(self, msg): + def display(self, msg): print(msg, file=sys.stderr) + error = display + ######################################## if __name__ == '__main__': @@ -96,5 +99,10 @@ if __name__ == '__main__': display.error("User interrupted execution") sys.exit(99) except Exception as e: + have_cli_options = cli is not None and cli.options is not None display.error("Unexpected Exception: %s" % str(e)) + if not have_cli_options or have_cli_options and cli.options.verbosity > 2: + display.display("the full traceback was:\n\n%s" % traceback.format_exc()) + else: + display.display("to see the full traceback, use -vvv") sys.exit(250)