diff options
author | Peter Sprygada <psprygada@ansible.com> | 2016-06-06 07:53:42 -0400 |
---|---|---|
committer | Peter Sprygada <psprygada@ansible.com> | 2016-06-07 06:33:35 -0400 |
commit | 6fc266019466633c45ae2034886f2f718626f74a (patch) | |
tree | a99baa6d547d3f83b194c1fd5cb502c50d2492f1 | |
parent | 8fd7e970a1769093e372bbd075c65f228a8c6710 (diff) | |
download | ansible-6fc266019466633c45ae2034886f2f718626f74a.tar.gz |
fixes issues with authenticating using ssh-agent for ios devices
Exception was raised when trying to use ssh-agent for authentication to
ios devices. This fix enables ssh-agent and enable use of password
protected ssh keys. There is one additional fix to capture authentication
exceptions nicely.
-rw-r--r-- | lib/ansible/module_utils/ios.py | 9 | ||||
-rw-r--r-- | lib/ansible/module_utils/shell.py | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/ios.py b/lib/ansible/module_utils/ios.py index 1ba6c1416e..08cf9f8fc4 100644 --- a/lib/ansible/module_utils/ios.py +++ b/lib/ansible/module_utils/ios.py @@ -77,9 +77,14 @@ class Cli(object): key_filename = self.module.params['ssh_keyfile'] timeout = self.module.params['timeout'] + allow_agent = (key_filename is not None) or (key_filename is None and password is None) + try: - self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, errors_re=CLI_ERRORS_RE) - self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename, timeout=timeout) + self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, + errors_re=CLI_ERRORS_RE) + self.shell.open(host, port=port, username=username, + password=password, key_filename=key_filename, + allow_agent=allow_agent, timeout=timeout) except ShellError: e = get_exception() msg = 'failed to connect to %s:%s - %s' % (host, port, str(e)) diff --git a/lib/ansible/module_utils/shell.py b/lib/ansible/module_utils/shell.py index 3ee770823e..873cce2cc0 100644 --- a/lib/ansible/module_utils/shell.py +++ b/lib/ansible/module_utils/shell.py @@ -27,6 +27,7 @@ except ImportError: try: import paramiko + from paramiko.ssh_exception import AuthenticationException HAS_PARAMIKO = True except ImportError: HAS_PARAMIKO = False @@ -110,6 +111,8 @@ class Shell(object): self.shell.settimeout(timeout) except socket.gaierror: raise ShellError("unable to resolve host name") + except AuthenticationException: + raise ShellError('Unable to authenticate to remote device') if self.kickstart: self.shell.sendall("\n") |