Skip to content

Commit

Permalink
Merge pull request ansible#9014 from willthames/paramiko_sudo_no_prompt
Browse files Browse the repository at this point in the history
Allow _remote_md5 to work with passwordless sudo even if password is supplied
  • Loading branch information
abadger committed Sep 22, 2014
2 parents cec7dd6 + 2303044 commit f16e107
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/ansible/runner/connection_plugins/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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:
Expand Down Expand Up @@ -259,6 +261,9 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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:

Expand All @@ -267,7 +272,7 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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 '''
Expand Down
7 changes: 6 additions & 1 deletion lib/ansible/runner/connection_plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable

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
Expand Down Expand Up @@ -351,6 +353,9 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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)

Expand All @@ -371,7 +376,7 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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 '''
Expand Down

0 comments on commit f16e107

Please sign in to comment.