Commit 4c84ba74 by Paul Durivage

Resolve su bug in paramiko libs

parent 24f11168
...@@ -176,7 +176,7 @@ class Connection(object): ...@@ -176,7 +176,7 @@ class Connection(object):
return ssh return ssh
def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False, executable='/bin/sh', in_data=None): def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable='/bin/sh', in_data=None, su=None, su_user=None):
''' run a command on the remote host ''' ''' run a command on the remote host '''
bufsize = 4096 bufsize = 4096
...@@ -188,7 +188,7 @@ class Connection(object): ...@@ -188,7 +188,7 @@ class Connection(object):
msg += ": %s" % str(e) msg += ": %s" % str(e)
raise errors.AnsibleConnectionFailed(msg) raise errors.AnsibleConnectionFailed(msg)
if not self.runner.sudo or not sudoable or in_data: if not (self.runner.sudo and sudoable) and not (self.runner.su and su) or in_data:
if executable: if executable:
quoted_command = executable + ' -c ' + pipes.quote(cmd) quoted_command = executable + ' -c ' + pipes.quote(cmd)
else: else:
...@@ -208,7 +208,7 @@ class Connection(object): ...@@ -208,7 +208,7 @@ class Connection(object):
sudo_output = '' sudo_output = ''
try: try:
chan.exec_command(shcmd) chan.exec_command(shcmd)
if self.runner.sudo_pass: if self.runner.sudo_pass or self.runner.su_pass:
while not sudo_output.endswith(prompt) and success_key not in sudo_output: while not sudo_output.endswith(prompt) and success_key not in sudo_output:
chunk = chan.recv(bufsize) chunk = chan.recv(bufsize)
if not chunk: if not chunk:
...@@ -220,7 +220,10 @@ class Connection(object): ...@@ -220,7 +220,10 @@ class Connection(object):
'closed waiting for password prompt') 'closed waiting for password prompt')
sudo_output += chunk sudo_output += chunk
if success_key not in sudo_output: if success_key not in sudo_output:
chan.sendall(self.runner.sudo_pass + '\n') if sudoable:
chan.sendall(self.runner.sudo_pass + '\n')
elif su:
chan.sendall(self.runner.su_pass + '\n')
except socket.timeout: except socket.timeout:
raise errors.AnsibleError('ssh timed out waiting for sudo.\n' + sudo_output) raise errors.AnsibleError('ssh timed out waiting for sudo.\n' + sudo_output)
......
...@@ -191,7 +191,7 @@ class Connection(object): ...@@ -191,7 +191,7 @@ class Connection(object):
msg += ": %s" % str(e) msg += ": %s" % str(e)
raise errors.AnsibleConnectionFailed(msg) raise errors.AnsibleConnectionFailed(msg)
if not self.runner.sudo or not sudoable: if not (self.runner.sudo and sudoable) and not (self.runner.su and su):
if executable: if executable:
quoted_command = executable + ' -c ' + pipes.quote(cmd) quoted_command = executable + ' -c ' + pipes.quote(cmd)
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment