mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Reboot - Fix errors when using Paramiko connection (#49002)
Different connection plugins return different data when throwing exceptions. The Paramiko connection plugin does not return a text sting, which caused an exception. The ssh connection plugin returns multi-line errors, which makes the debug logs harder to read. Only return the last line in that case in order to make the logs more readable. When experiencing a connection failure, reset the connection. Add reset() to paramiko_ssh Indicate thet conection state is False when running close(). This is needed by the ensure_connected() decorator to work properly. Co-authored-by: Matt Martz <matt@sivel.net>
This commit is contained in:
@@ -528,6 +528,10 @@ class Connection(ConnectionBase):
|
||||
|
||||
f.close()
|
||||
|
||||
def reset(self):
|
||||
self.close()
|
||||
self._connect()
|
||||
|
||||
def close(self):
|
||||
''' terminate the connection '''
|
||||
|
||||
@@ -585,7 +589,7 @@ class Connection(ConnectionBase):
|
||||
|
||||
os.rename(tmp_keyfile.name, self.keyfile)
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
|
||||
# unable to save keys, including scenario when key was invalid
|
||||
# and caught earlier
|
||||
@@ -593,3 +597,4 @@ class Connection(ConnectionBase):
|
||||
fcntl.lockf(KEY_LOCK, fcntl.LOCK_UN)
|
||||
|
||||
self.ssh.close()
|
||||
self._connected = False
|
||||
|
||||
Reference in New Issue
Block a user