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

@ -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()