From de77f337968ba78e4c002c7ef4c71b2ae698ef9a Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 5 Sep 2014 08:42:31 -0500 Subject: [PATCH 1/2] Don't throw away useful stdout and stderr. Fixes #8418 When supplying a sudo password to a server that uses passwordless sudo, we should not throw away useful stdout and stderr. This is particularly important for modules that perform md5 checks as part of the pre module execution. --- lib/ansible/runner/connection_plugins/ssh.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py index fdf5f0dc6e5..cbba7659035 100644 --- a/lib/ansible/runner/connection_plugins/ssh.py +++ b/lib/ansible/runner/connection_plugins/ssh.py @@ -301,6 +301,8 @@ class Connection(object): self._send_password() + no_prompt_out = '' + no_prompt_err = '' if (self.runner.sudo and sudoable and self.runner.sudo_pass) or \ (self.runner.su and su and self.runner.su_pass): # several cases are handled for sudo privileges with password @@ -351,6 +353,9 @@ class Connection(object): stdin.write(self.runner.sudo_pass + '\n') elif su: stdin.write(self.runner.su_pass + '\n') + else: + no_prompt_out += sudo_output + no_prompt_err += sudo_errput (returncode, stdout, stderr) = self._communicate(p, stdin, in_data, su=su, sudoable=sudoable, prompt=prompt) @@ -371,7 +376,7 @@ class Connection(object): if p.returncode == 255 and (in_data or self.runner.module_name == 'raw'): raise errors.AnsibleError('SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh') - return (p.returncode, '', stdout, stderr) + return (p.returncode, '', no_prompt_out + stdout, no_prompt_err + stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to remote ''' From 2303044ffc68f8708529ffe236d41d491d4093ca Mon Sep 17 00:00:00 2001 From: Will Thames Date: Tue, 16 Sep 2014 10:22:36 +1000 Subject: [PATCH 2/2] Applied fix for sudo with no prompt to paramiko Effectively reproduces @sivel's work from #8900 but for the paramiko connection. Fixes #8418 when using paramiko This allows `_remote_md5` to work if a sudo password is passed in when no sudo password is required. --- lib/ansible/runner/connection_plugins/paramiko_ssh.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/connection_plugins/paramiko_ssh.py b/lib/ansible/runner/connection_plugins/paramiko_ssh.py index 5e3cfc55a96..dc02b047f80 100644 --- a/lib/ansible/runner/connection_plugins/paramiko_ssh.py +++ b/lib/ansible/runner/connection_plugins/paramiko_ssh.py @@ -204,6 +204,8 @@ class Connection(object): msg += ": %s" % str(e) raise errors.AnsibleConnectionFailed(msg) + no_prompt_out = '' + no_prompt_err = '' if not (self.runner.sudo and sudoable) and not (self.runner.su and su): if executable: @@ -259,6 +261,9 @@ class Connection(object): chan.sendall(self.runner.sudo_pass + '\n') elif su: chan.sendall(self.runner.su_pass + '\n') + else: + no_prompt_out += sudo_output + no_prompt_err += sudo_output except socket.timeout: @@ -267,7 +272,7 @@ class Connection(object): stdout = ''.join(chan.makefile('rb', bufsize)) stderr = ''.join(chan.makefile_stderr('rb', bufsize)) - return (chan.recv_exit_status(), '', stdout, stderr) + return (chan.recv_exit_status(), '', no_prompt_out + stdout, no_prompt_out + stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to remote '''