From e65ef09aa9a5a134fb8c2404db9247837dd1dc30 Mon Sep 17 00:00:00 2001 From: Kedar K <4506537+kedarX@users.noreply.github.com> Date: Mon, 27 Nov 2017 18:47:17 +0530 Subject: [PATCH] - Fix authentication failure with paramiko when using password mode (#33303) - break out of loop when paramiko stream is closed --- lib/ansible/plugins/connection/network_cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index be7624c05da..a3e9e04ccb4 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -162,7 +162,7 @@ class Connection(ConnectionBase): return p = connection_loader.get('paramiko', self._play_context, '/dev/null') - p.set_options(direct={'look_for_keys': bool(self._play_context.password and not self._play_context.private_key_file)}) + p.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)}) p.force_persistence = self.force_persistence ssh = p._connect() @@ -261,6 +261,10 @@ class Connection(ConnectionBase): while True: data = self._ssh_shell.recv(256) + # when a channel stream is closed, received data will be empty + if not data: + break + recv.write(data) offset = recv.tell() - 256 if recv.tell() > 256 else 0 recv.seek(offset)