From b72b14fdf2c0caa7cd4b6b4695c134f9af174752 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 17 Feb 2016 14:14:41 +0000 Subject: [PATCH] minor bugfix that will catch connection errors in iosxr This commit fixes a situation where connection errors would be caught but no useful information display. The connection error is now caught and emitted in a call to fail_json --- lib/ansible/module_utils/iosxr.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/iosxr.py b/lib/ansible/module_utils/iosxr.py index 7ca360c5efd..e2c7c983916 100644 --- a/lib/ansible/module_utils/iosxr.py +++ b/lib/ansible/module_utils/iosxr.py @@ -49,7 +49,12 @@ class Cli(object): password = self.module.params['password'] self.shell = Shell() - self.shell.open(host, port=port, username=username, password=password) + + try: + self.shell.open(host, port=port, username=username, password=password) + except Exception, exc: + msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc)) + self.module.fail_json(msg=msg) def send(self, commands): return self.shell.send(commands)