partial become support for local connection plugin

pull/11306/head
Brian Coca 9 years ago
parent 671118ba71
commit 7c65f3ddd7

@ -22,8 +22,8 @@ import traceback
import os import os
import shutil import shutil
import subprocess import subprocess
#import select import select
#import fcntl import fcntl
import ansible.constants as C import ansible.constants as C
@ -51,18 +51,17 @@ class Connection(ConnectionBase):
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True): def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True):
''' run a command on the local host ''' ''' run a command on the local host '''
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data) super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable)
debug("in local.exec_command()") debug("in local.exec_command()")
# su requires to be run from a terminal, and therefore isn't supported here (yet?)
#if self._connection_info.su:
# raise AnsibleError("Internal Error: this module does not support running commands via su")
if in_data: if in_data:
raise AnsibleError("Internal Error: this module does not support optimized module pipelining") raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else None executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else None
if sudoable:
cmd, self.prompt, self.success_key = self._connection_info.make_become_cmd(cmd)
self._display.vvv("{0} EXEC {1}".format(self._connection_info.remote_addr, cmd)) self._display.vvv("{0} EXEC {1}".format(self._connection_info.remote_addr, cmd))
# FIXME: cwd= needs to be set to the basedir of the playbook # FIXME: cwd= needs to be set to the basedir of the playbook
debug("opening command with Popen()") debug("opening command with Popen()")
@ -76,31 +75,28 @@ class Connection(ConnectionBase):
) )
debug("done running command with Popen()") debug("done running command with Popen()")
# FIXME: more su/sudo stuff if self.prompt:
#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)
# fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_GETFL) | os.O_NONBLOCK)
# fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) become_output = ''
# fcntl.fcntl(p.stderr, fcntl.F_SETFL, while not self.check_become_success(become_output) and not self.check_password_prompt(become_output):
# fcntl.fcntl(p.stderr, fcntl.F_GETFL) | os.O_NONBLOCK)
# sudo_output = '' rfd, wfd, efd = select.select([p.stdout, p.stderr], [], [p.stdout, p.stderr], self._connection_info.timeout)
# while not sudo_output.endswith(prompt) and success_key not in sudo_output: if p.stdout in rfd:
# rfd, wfd, efd = select.select([p.stdout, p.stderr], [], chunk = p.stdout.read()
# [p.stdout, p.stderr], self.runner.timeout) elif p.stderr in rfd:
# if p.stdout in rfd: chunk = p.stderr.read()
# chunk = p.stdout.read() else:
# elif p.stderr in rfd: stdout, stderr = p.communicate()
# chunk = p.stderr.read() raise AnsibleError('timeout waiting for privilege escalation password prompt:\n' + become_output)
# else: if not chunk:
# stdout, stderr = p.communicate() stdout, stderr = p.communicate()
# raise AnsibleError('timeout waiting for sudo password prompt:\n' + sudo_output) raise AnsibleError('privilege output closed while waiting for password prompt:\n' + become_output)
# if not chunk: become_output += chunk
# stdout, stderr = p.communicate() if not self.check_become_success(become_output):
# raise AnsibleError('sudo output closed while waiting for password prompt:\n' + sudo_output) p.stdin.write(self._connection_info.become_pass + '\n')
# sudo_output += chunk fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
# if success_key not in sudo_output: fcntl.fcntl(p.stderr, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_GETFL) & ~os.O_NONBLOCK)
# p.stdin.write(self.runner.sudo_pass + '\n')
# fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
# fcntl.fcntl(p.stderr, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_GETFL) & ~os.O_NONBLOCK)
debug("getting output with communicate()") debug("getting output with communicate()")
stdout, stderr = p.communicate() stdout, stderr = p.communicate()

Loading…
Cancel
Save