more debug logs for free, network_cli, paramiko and add hostname context to debugging messages (#39205)

* Add hostname context to debugging messages
* Set paramiko's channel
This commit is contained in:
jctanner 2018-04-26 17:10:28 -04:00 committed by GitHub
parent f91d961cb4
commit bbfe7a8b2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 11 deletions

View file

@ -228,6 +228,7 @@ class Connection(ConnectionBase):
''' SSH based connections with Paramiko '''
transport = 'paramiko'
_log_channel = None
def _cache_key(self):
return "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
@ -240,6 +241,10 @@ class Connection(ConnectionBase):
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
return self
def _set_log_channel(self, name):
'''Mimic paramiko.SSHClient.set_log_channel'''
self._log_channel = name
def _parse_proxy_command(self, port=22):
proxy_command = None
# Parse ansible_ssh_common_args, specifically looking for ProxyCommand
@ -297,6 +302,10 @@ class Connection(ConnectionBase):
ssh = paramiko.SSHClient()
# override paramiko's default logger name
if self._log_channel is not None:
ssh.set_log_channel(self._log_channel)
self.keyfile = os.path.expanduser("~/.ssh/known_hosts")
if self.get_option('host_key_checking'):