Skip to content

Commit

Permalink
Conditionally add auth_timeout to ssh.connect
Browse files Browse the repository at this point in the history
Renamed sock_kwarg to ssh_connect_kwargs and conditionally added the
auth_timeout parameter based on the installed paramiko version.
  • Loading branch information
orgito committed Jan 4, 2019
1 parent e7f21dd commit 6c41e97
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions lib/ansible/plugins/connection/paramiko_ssh.py
Expand Up @@ -324,7 +324,7 @@ def _connect_uncached(self):
pass # file was not found, but not required to function
ssh.load_system_host_keys()

sock_kwarg = self._parse_proxy_command(port)
ssh_connect_kwargs = self._parse_proxy_command(port)

ssh.set_missing_host_key_policy(MyAddPolicy(self._new_stdin, self))

Expand All @@ -340,30 +340,19 @@ def _connect_uncached(self):

# paramiko 2.2 introduced auth_timeout parameter
if LooseVersion(paramiko.__version__) >= LooseVersion('2.2.0'):
ssh.connect(
self._play_context.remote_addr.lower(),
username=self._play_context.remote_user,
allow_agent=allow_agent,
look_for_keys=self.get_option('look_for_keys'),
key_filename=key_filename,
password=self._play_context.password,
timeout=self._play_context.timeout,
auth_timeout=self._play_context.timeout,
port=port,
**sock_kwarg
)
else:
ssh.connect(
self._play_context.remote_addr.lower(),
username=self._play_context.remote_user,
allow_agent=allow_agent,
look_for_keys=self.get_option('look_for_keys'),
key_filename=key_filename,
password=self._play_context.password,
timeout=self._play_context.timeout,
port=port,
**sock_kwarg
)
ssh_connect_kwargs['auth_timeout'] = self._play_context.timeout

ssh.connect(
self._play_context.remote_addr.lower(),
username=self._play_context.remote_user,
allow_agent=allow_agent,
look_for_keys=self.get_option('look_for_keys'),
key_filename=key_filename,
password=self._play_context.password,
timeout=self._play_context.timeout,
port=port,
**ssh_connect_kwargs
)
except paramiko.ssh_exception.BadHostKeyException as e:
raise AnsibleConnectionFailure('host key mismatch for %s' % e.hostname)
except Exception as e:
Expand Down

0 comments on commit 6c41e97

Please sign in to comment.