mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
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:
parent
f91d961cb4
commit
bbfe7a8b2f
4 changed files with 30 additions and 11 deletions
|
@ -157,6 +157,7 @@ options:
|
|||
- name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
|
||||
"""
|
||||
|
||||
import getpass
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
@ -221,6 +222,11 @@ class Connection(ConnectionBase):
|
|||
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
|
||||
return getattr(self._cliconf, name)
|
||||
|
||||
def _get_log_channel(self):
|
||||
name = "p=%s u=%s | " % (os.getpid(), getpass.getuser())
|
||||
name += "paramiko [%s]" % self._play_context.remote_addr
|
||||
return name
|
||||
|
||||
def get_prompt(self):
|
||||
"""Returns the current prompt from the device"""
|
||||
return self._matched_prompt
|
||||
|
@ -284,6 +290,7 @@ class Connection(ConnectionBase):
|
|||
return
|
||||
|
||||
self.paramiko_conn = connection_loader.get('paramiko', self._play_context, '/dev/null')
|
||||
self.paramiko_conn._set_log_channel(self._get_log_channel())
|
||||
self.paramiko_conn.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)})
|
||||
self.paramiko_conn.force_persistence = self.force_persistence
|
||||
ssh = self.paramiko_conn._connect()
|
||||
|
@ -363,7 +370,7 @@ class Connection(ConnectionBase):
|
|||
'''
|
||||
# only close the connection if its connected.
|
||||
if self._connected:
|
||||
display.debug("closing ssh connection to device")
|
||||
display.debug("closing ssh connection to device", host=self._play_context.remote_addr)
|
||||
if self._ssh_shell:
|
||||
display.debug("firing event: on_close_shell()")
|
||||
self._terminal.on_close_shell()
|
||||
|
|
|
@ -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'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue