From f42b6237d99a9dc7398143219f9d928943fce4c8 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sun, 5 Jul 2015 17:46:51 -0400 Subject: [PATCH] now has display of last resort moved all display/color/err to use display.error now also capture generic exceptions if they happen (never should!) --- bin/ansible | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/bin/ansible b/bin/ansible index 2c8c6f3d22b..03a50fd9438 100755 --- a/bin/ansible +++ b/bin/ansible @@ -18,7 +18,7 @@ # along with Ansible. If not, see . ######################################################## -from __future__ import (absolute_import) +from __future__ import (absolute_import, print_function) __metaclass__ = type __requires__ = ['ansible'] @@ -38,10 +38,17 @@ import sys from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError from ansible.utils.display import Display -######################################################## +######################################## +### OUTPUT OF LAST RESORT ### +class LastResort(object): + def error(self, msg): + print(msg, file=sys.stderr) + +######################################## if __name__ == '__main__': + display = LastResort() cli = None me = os.path.basename(sys.argv[0]) @@ -70,21 +77,24 @@ if __name__ == '__main__': except AnsibleOptionsError as e: cli.parser.print_help() - display.display(str(e), stderr=True, color='red') + display.error(str(e)) sys.exit(5) except AnsibleParserError as e: - display.display(str(e), stderr=True, color='red') + display.error(str(e)) sys.exit(4) # TQM takes care of these, but leaving comment to reserve the exit codes # except AnsibleHostUnreachable as e: -# display.display(str(e), stderr=True, color='red') +# display.error(str(e)) # sys.exit(3) # except AnsibleHostFailed as e: -# display.display(str(e), stderr=True, color='red') +# display.error(str(e)) # sys.exit(2) except AnsibleError as e: - display.display(str(e), stderr=True, color='red') + display.error(str(e)) sys.exit(1) except KeyboardInterrupt: - display.error("interrupted") + display.error("User interrupted execution") sys.exit(99) + except Exception as e: + display.error("Unexpected Exception: %s" % str(e)) + sys.exit(250)