mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 12:03:58 -07:00
Implement friendlier error handling.
Generic AnsibleError exception + host inventory missing exception. First shot at catching these in a generic way in bin/ansible*.
This commit is contained in:
parent
ce85222fa6
commit
dfd2c6dce3
4 changed files with 57 additions and 10 deletions
13
bin/ansible
13
bin/ansible
|
@ -34,6 +34,7 @@ import ansible.runner
|
|||
import ansible.playbook
|
||||
import ansible.constants as C
|
||||
from ansible.utils import *
|
||||
from ansible.errors import *
|
||||
|
||||
########################################################
|
||||
|
||||
|
@ -193,7 +194,11 @@ class Cli(object):
|
|||
if __name__ == '__main__':
|
||||
cli = Cli()
|
||||
(options, args) = cli.parse()
|
||||
(runner, results) = cli.run(options, args)
|
||||
cli.output(runner, results, options, args)
|
||||
|
||||
|
||||
try:
|
||||
(runner, results) = cli.run(options, args)
|
||||
except AnsibleError as e:
|
||||
# Generic handler for ansible specific errors
|
||||
print e
|
||||
sys.exit(1)
|
||||
else:
|
||||
cli.output(runner, results, options, args)
|
||||
|
|
|
@ -96,15 +96,14 @@ def main(args):
|
|||
remote_pass=sshpass,
|
||||
callbacks=PlaybookCallbacks()
|
||||
)
|
||||
pb.run()
|
||||
try:
|
||||
pb.run()
|
||||
except AnsibleError as e:
|
||||
print e
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue