diff --git a/lib/ansible/module_utils/iosxr.py b/lib/ansible/module_utils/iosxr.py index 9686adc7f5..32c5662ec5 100644 --- a/lib/ansible/module_utils/iosxr.py +++ b/lib/ansible/module_utils/iosxr.py @@ -48,7 +48,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)