mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
nicer error on bad ansible config (#30461)
* nicer error on bad ansible config
This commit is contained in:
parent
24d4787b2d
commit
76aaaf127b
1 changed files with 9 additions and 6 deletions
15
bin/ansible
15
bin/ansible
|
@ -37,15 +37,12 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import ansible.constants as C
|
|
||||||
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
||||||
from ansible.utils.display import Display
|
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
########################################
|
|
||||||
# OUTPUT OF LAST RESORT
|
|
||||||
class LastResort(object):
|
class LastResort(object):
|
||||||
|
# OUTPUT OF LAST RESORT
|
||||||
def display(self, msg, log_only=None):
|
def display(self, msg, log_only=None):
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
@ -53,11 +50,17 @@ class LastResort(object):
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
########################################
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
display = LastResort()
|
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
|
cli = None
|
||||||
me = os.path.basename(sys.argv[0])
|
me = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue