From c90ab8856d82d575e7283a7438fbc4f0b386aa2e Mon Sep 17 00:00:00 2001 From: Matthew Stoltenberg Date: Tue, 9 Feb 2016 15:08:33 -0700 Subject: [PATCH] paramiko transport appears to hang if it gets a sudo lecture * bring paramiko transport closer to ssh transport in how it deals with prompt --- .../plugins/connection/paramiko_ssh.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py index 52bbdf05d8..c924c762af 100644 --- a/lib/ansible/plugins/connection/paramiko_ssh.py +++ b/lib/ansible/plugins/connection/paramiko_ssh.py @@ -230,13 +230,9 @@ class Connection(ConnectionBase): chan.exec_command(cmd) if self._play_context.prompt: passprompt = False - while True: + become_sucess = False + while not (become_sucess or passprompt): display.debug('Waiting for Privilege Escalation input') - if self.check_become_success(become_output): - break - elif self.check_password_prompt(become_output): - passprompt = True - break chunk = chan.recv(bufsize) display.debug("chunk is: %s" % chunk) @@ -247,6 +243,17 @@ class Connection(ConnectionBase): break #raise AnsibleError('ssh connection closed waiting for password prompt') become_output += chunk + + # need to check every line because we might get lectured + # and we might get the middle of a line in a chunk + for l in become_output.splitlines(True): + if self.check_become_success(l): + become_sucess = True + break + elif self.check_password_prompt(l): + passprompt = True + break + if passprompt: if self._play_context.become and self._play_context.become_pass: chan.sendall(self._play_context.become_pass + '\n')