From 7e73d6c604f7332276d175b8a5378c34e930d3e9 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Wed, 20 Jun 2012 14:06:24 -0400 Subject: [PATCH 1/3] add -q to handle stdout/stderr being combined, add catch for ControlPersist not existing in ssh for rhel6, etc --- lib/ansible/runner/connection/ssh.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index 4870adc9926..fc780e0c5d1 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -59,7 +59,7 @@ class SSHConnection(object): def exec_command(self, cmd, tmp_path,sudo_user,sudoable=False): ''' run a command on the remote host ''' - ssh_cmd = ["ssh", "-tt"] + self.common_args + [self.userhost] + ssh_cmd = ["ssh", "-tt", "-q"] + self.common_args + [self.userhost] if self.runner.sudo and sudoable: # Rather than detect if sudo wants a password this time, -k makes # sudo always ask for a password if one is required. The "--" @@ -97,6 +97,10 @@ class SSHConnection(object): ssh_cmd.append(cmd) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if p.returncode != 0 and p.stderr and p.stderr.read().find('Bad configuration option: ControlPersist') != -1: + raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again') + return (p.stdin, p.stdout, '') def put_file(self, in_path, out_path): From 0bbea3e684b1c727f00cb89b2ec300c2e81aecb1 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 20 Jun 2012 20:22:48 +0200 Subject: [PATCH 2/3] Wait for process to finish and then parse output --- lib/ansible/runner/connection/ssh.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index fc780e0c5d1..8c8693a1b7f 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -97,11 +97,19 @@ class SSHConnection(object): ssh_cmd.append(cmd) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - if p.returncode != 0 and p.stderr and p.stderr.read().find('Bad configuration option: ControlPersist') != -1: + + # We can't use p.communicate here because the ControlMaster may have stdout open as well + p.stdin.close() + stdout = '' + while p.poll() is None: + rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1) + if p.stdout in rfd: + stdout += os.read(p.stdout.fileno(), 1024) + + if p.returncode != 0 and stdout.find('Bad configuration option: ControlPersist') != -1: raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again') - return (p.stdin, p.stdout, '') + return ('', stdout, '') def put_file(self, in_path, out_path): ''' transfer a file from local to remote ''' From 92dd59f64171fef4612c10cd376776b0101bcdc0 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 20 Jun 2012 20:23:11 +0200 Subject: [PATCH 3/3] Merge stdout and stderr for non-sudo --- lib/ansible/runner/connection/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index 8c8693a1b7f..f2d6ffe2d22 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -96,7 +96,7 @@ class SSHConnection(object): else: ssh_cmd.append(cmd) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # We can't use p.communicate here because the ControlMaster may have stdout open as well p.stdin.close()