summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2017-09-19 10:50:28 -0400
committerGitHub <noreply@github.com>2017-09-19 10:50:28 -0400
commit76aaaf127bea947c5eb559f79cc7926aabdababd (patch)
tree81bfbaef4454454cc89f78828a377501d278941e
parent24d4787b2d3bf531c048fe3cdce0534180193475 (diff)
downloadansible-76aaaf127bea947c5eb559f79cc7926aabdababd.tar.gz
nicer error on bad ansible config (#30461)
* nicer error on bad ansible config
-rwxr-xr-xbin/ansible15
1 files changed, 9 insertions, 6 deletions
diff --git a/bin/ansible b/bin/ansible
index 6a40d9718f..7eaa5337b1 100755
--- a/bin/ansible
+++ b/bin/ansible
@@ -37,15 +37,12 @@ import shutil
import sys
import traceback
-import ansible.constants as C
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
-from ansible.utils.display import Display
from ansible.module_utils._text import to_text
-########################################
-# OUTPUT OF LAST RESORT
class LastResort(object):
+ # OUTPUT OF LAST RESORT
def display(self, msg, log_only=None):
print(msg, file=sys.stderr)
@@ -53,11 +50,17 @@ class LastResort(object):
print(msg, file=sys.stderr)
-########################################
-
if __name__ == '__main__':
display = LastResort()
+
+ try: # bad ANSIBLE_CONFIG or config options can force ugly stacktrace
+ import ansible.constants as C
+ from ansible.utils.display import Display
+ except AnsibleOptionsError as e:
+ display.error(to_text(e), wrap_text=False)
+ sys.exit(5)
+
cli = None
me = os.path.basename(sys.argv[0])