Skip to content

Commit

Permalink
Merge pull request ansible#16148 from privateip/working
Browse files Browse the repository at this point in the history
fixes issues with authenticating using ssh-agent for ios devices
  • Loading branch information
privateip committed Jun 7, 2016
2 parents 4eedad5 + 0a87651 commit 596b32f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ansible/module_utils/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ def connect(self, **kwargs):
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))
Expand Down
3 changes: 3 additions & 0 deletions lib/ansible/module_utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

try:
import paramiko
from paramiko.ssh_exception import AuthenticationException
HAS_PARAMIKO = True
except ImportError:
HAS_PARAMIKO = False
Expand Down Expand Up @@ -111,6 +112,8 @@ def open(self, host, port=22, username=None, password=None,
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")
Expand Down

0 comments on commit 596b32f

Please sign in to comment.