diff --git a/lib/ansible/runner/connection_plugins/paramiko_ssh.py b/lib/ansible/runner/connection_plugins/paramiko_ssh.py index d5ef219821..d6e7a5015d 100644 --- a/lib/ansible/runner/connection_plugins/paramiko_ssh.py +++ b/lib/ansible/runner/connection_plugins/paramiko_ssh.py @@ -125,10 +125,11 @@ class Connection(object): prompt = '[sudo via ansible, key=%s] password: ' % randbits sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % ( prompt, sudo_user, pipes.quote(cmd)) - vvv("EXEC %s" % sudocmd, host=self.host) + shcmd = '/bin/sh -c ' + pipes.quote(sudocmd) + vvv("EXEC %s" % shcmd, host=self.host) sudo_output = '' try: - chan.exec_command(sudocmd) + chan.exec_command(shcmd) if self.runner.sudo_pass: while not sudo_output.endswith(prompt): chunk = chan.recv(bufsize) diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py index b10210d56e..5a33774bbc 100644 --- a/lib/ansible/runner/connection_plugins/ssh.py +++ b/lib/ansible/runner/connection_plugins/ssh.py @@ -93,10 +93,8 @@ class Connection(object): prompt = '[sudo via ansible, key=%s] password: ' % randbits sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % ( prompt, sudo_user, pipes.quote(cmd)) - sudo_output = '' - ssh_cmd.append(sudocmd) - else: - ssh_cmd.append(cmd) + cmd = sudocmd + ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd)) vvv("EXEC %s" % ssh_cmd, host=self.host) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, @@ -107,6 +105,7 @@ class Connection(object): if self.runner.sudo and sudoable and self.runner.sudo_pass: fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) + sudo_output = '' while not sudo_output.endswith(prompt): rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], self.runner.timeout)