From 389602b8dda3f9bb8cf189745041e69c77a0fa29 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Fri, 15 Nov 2013 12:19:10 -0700 Subject: [PATCH] Merge pull request #4920 from iffy/ansible Collect all stdout over ssh transport before returning data --- lib/ansible/runner/connection_plugins/ssh.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py index 5ee45ba6a9..0d6c3d8a7f 100644 --- a/lib/ansible/runner/connection_plugins/ssh.py +++ b/lib/ansible/runner/connection_plugins/ssh.py @@ -216,8 +216,9 @@ class Connection(object): # We can't use p.communicate here because the ControlMaster may have stdout open as well stdout = '' stderr = '' + rpipes = [p.stdout, p.stderr] while True: - rfd, wfd, efd = select.select([p.stdout, p.stderr], [], [p.stdout, p.stderr], 1) + rfd, wfd, efd = select.select(rpipes, [], rpipes, 1) # fail early if the sudo password is wrong if self.runner.sudo and sudoable and self.runner.sudo_pass: @@ -230,15 +231,14 @@ class Connection(object): dat = os.read(p.stdout.fileno(), 9000) stdout += dat if dat == '': - p.wait() - break - elif p.stderr in rfd: + rpipes.remove(p.stdout) + if p.stderr in rfd: dat = os.read(p.stderr.fileno(), 9000) stderr += dat if dat == '': - p.wait() - break - elif p.poll() is not None: + rpipes.remove(p.stderr) + if not rpipes or p.poll() is not None: + p.wait() break stdin.close() # close stdin after we read from stdout (see also issue #848)