Properly report exception causes particularly connection exceptions contacting the consul agent

This commit is contained in:
Steve Gargan 2015-03-16 16:50:53 +00:00 committed by Matt Clay
parent e701972186
commit b5faf88494
4 changed files with 25 additions and 20 deletions

View file

@ -143,6 +143,7 @@ except ImportError, e:
"see http://python-consul.readthedocs.org/en/latest/#installation'" "see http://python-consul.readthedocs.org/en/latest/#installation'"
sys.exit(1) sys.exit(1)
from requests.exceptions import ConnectionError
def register_with_consul(module): def register_with_consul(module):
@ -453,11 +454,11 @@ def main():
) )
try: try:
register_with_consul(module) register_with_consul(module)
except IOError, e: except ConnectionError, e:
error = e.read() module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
if not error: module.params.get('host'), module.params.get('port'), str(e)))
error = str(e) except Exception, e:
module.fail_json(msg=error) module.fail_json(msg=str(e))
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

View file

@ -92,6 +92,7 @@ except ImportError:
" see https://pypi.python.org/pypi/pyhcl'" " see https://pypi.python.org/pypi/pyhcl'"
sys.exit(1) sys.exit(1)
from requests.exceptions import ConnectionError
def execute(module): def execute(module):
@ -284,11 +285,11 @@ def main():
try: try:
execute(module) execute(module)
except IOError, e: except ConnectionError, e:
error = e.read() module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
if not error: module.params.get('host'), module.params.get('port'), str(e)))
error = str(e) except Exception, e:
module.fail_json(msg=error) module.fail_json(msg=str(e))
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

View file

@ -117,6 +117,7 @@ except ImportError, e:
see http://python-consul.readthedocs.org/en/latest/#installation'""" see http://python-consul.readthedocs.org/en/latest/#installation'"""
sys.exit(1) sys.exit(1)
from requests.exceptions import ConnectionError
def execute(module): def execute(module):
@ -227,11 +228,12 @@ def main():
try: try:
execute(module) execute(module)
except IOError, e: except ConnectionError, e:
error = e.read() module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
if not error: module.params.get('host'), module.params.get('port'), str(e)))
error = str(e) except Exception, e:
module.fail_json(msg=error) module.fail_json(msg=str(e))
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

View file

@ -80,6 +80,7 @@ except ImportError, e:
"http://python-consul.readthedocs.org/en/latest/#installation'" "http://python-consul.readthedocs.org/en/latest/#installation'"
sys.exit(1) sys.exit(1)
from requests.errors import ConnectionError
def execute(module): def execute(module):
@ -202,11 +203,11 @@ def main():
try: try:
execute(module) execute(module)
except IOError, e: except ConnectionError, e:
error = e.read() module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
if not error: module.params.get('host'), module.params.get('port'), str(e)))
error = str(e) except Exception, e:
module.fail_json(msg=error) module.fail_json(msg=str(e))
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *