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:
Tim Bielawa 2012-03-12 23:11:54 -04:00
commit dfd2c6dce3
4 changed files with 57 additions and 10 deletions

View file

@ -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)

View file

@ -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:]))