From 37d8242e448ae4f767dd5d0a89e7f487324a945a Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Fri, 17 Nov 2017 13:09:02 -0500 Subject: [PATCH] Fix hang on unkown host key for network_cli (#32937) * Don't prompt on force_persistent either * Propagate persistence setting to lower paramiko connection --- lib/ansible/plugins/connection/network_cli.py | 5 ++--- lib/ansible/plugins/connection/paramiko_ssh.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 167d001bb54..b784defaa44 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -78,7 +78,6 @@ class Connection(ConnectionBase): def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) - self.ssh = None self._ssh_shell = None self._matched_prompt = None @@ -164,12 +163,12 @@ class Connection(ConnectionBase): 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.force_persistence = self.force_persistence ssh = p._connect() - self.ssh = ssh.ssh display.vvvv('ssh connection done, setting terminal', host=self._play_context.remote_addr) - self._ssh_shell = self.ssh.invoke_shell() + self._ssh_shell = ssh.ssh.invoke_shell() self._ssh_shell.settimeout(self._play_context.timeout) network_os = self._play_context.network_os diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py index 93698836573..1466c65721c 100644 --- a/lib/ansible/plugins/connection/paramiko_ssh.py +++ b/lib/ansible/plugins/connection/paramiko_ssh.py @@ -188,7 +188,7 @@ class MyAddPolicy(object): fingerprint = hexlify(key.get_fingerprint()) ktype = key.get_name() - if C.USE_PERSISTENT_CONNECTIONS: + if C.USE_PERSISTENT_CONNECTIONS or self.connection.force_persistence: # don't print the prompt string since the user cannot respond # to the question anyway raise AnsibleError(AUTHENTICITY_MSG[1:92] % (hostname, ktype, fingerprint))