mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Enable su support in paramkio; disable su support in fireball, local, accelerate, chroot, jail, funcd connection plugins
This commit is contained in:
parent
c95be4ceaa
commit
ab6ee1a282
7 changed files with 36 additions and 14 deletions
|
@ -159,9 +159,12 @@ class Connection(object):
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
raise errors.AnsibleError("timed out while waiting to receive data")
|
raise errors.AnsibleError("timed out while waiting to receive data")
|
||||||
|
|
||||||
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 '''
|
||||||
|
|
||||||
|
if su or su_user:
|
||||||
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via su")
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,12 @@ class Connection(object):
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
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 chroot '''
|
''' run a command on the chroot '''
|
||||||
|
|
||||||
|
if su or su_user:
|
||||||
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via su")
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Connection(object):
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
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, sudoable=False, executable='/bin/sh', in_data=None, su_user=None, su=None):
|
||||||
''' run a command on the remote host '''
|
''' run a command on the remote host '''
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
|
@ -76,9 +76,9 @@ class Connection(object):
|
||||||
|
|
||||||
vvv("EXEC COMMAND %s" % cmd)
|
vvv("EXEC COMMAND %s" % cmd)
|
||||||
|
|
||||||
if self.runner.sudo and sudoable:
|
if (self.runner.sudo and sudoable) or (self.runner.su and su):
|
||||||
raise errors.AnsibleError(
|
raise errors.AnsibleError(
|
||||||
"When using fireball, do not specify sudo to run your tasks. " +
|
"When using fireball, do not specify sudo or su to run your tasks. " +
|
||||||
"Instead sudo the fireball action with sudo. " +
|
"Instead sudo the fireball action with sudo. " +
|
||||||
"Task will communicate with the fireball already running in sudo mode."
|
"Task will communicate with the fireball already running in sudo mode."
|
||||||
)
|
)
|
||||||
|
|
|
@ -53,10 +53,13 @@ class Connection(object):
|
||||||
self.client = fc.Client(self.host)
|
self.client = fc.Client(self.host)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False,
|
def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False,
|
||||||
executable='/bin/sh', in_data=None):
|
executable='/bin/sh', in_data=None, su=None, su_user=None):
|
||||||
''' run a command on the remote minion '''
|
''' run a command on the remote minion '''
|
||||||
|
|
||||||
|
if su or su_user:
|
||||||
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via su")
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
|
|
|
@ -91,9 +91,12 @@ class Connection(object):
|
||||||
local_cmd = '%s "%s" %s' % (self.jexec_cmd, self.jail, cmd)
|
local_cmd = '%s "%s" %s' % (self.jexec_cmd, self.jail, cmd)
|
||||||
return local_cmd
|
return local_cmd
|
||||||
|
|
||||||
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 chroot '''
|
''' run a command on the chroot '''
|
||||||
|
|
||||||
|
if su or su_user:
|
||||||
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via su")
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,13 @@ class Connection(object):
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
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 local host '''
|
''' run a command on the local host '''
|
||||||
|
|
||||||
|
# su requires to be run from a terminal, and therefore isn't supported here (yet?)
|
||||||
|
if su or su_user:
|
||||||
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via su")
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
|
|
|
@ -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 '''
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
|
@ -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 sudo) 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:
|
||||||
|
@ -206,12 +206,15 @@ class Connection(object):
|
||||||
chan.get_pty(term=os.getenv('TERM', 'vt100'),
|
chan.get_pty(term=os.getenv('TERM', 'vt100'),
|
||||||
width=int(os.getenv('COLUMNS', 0)),
|
width=int(os.getenv('COLUMNS', 0)),
|
||||||
height=int(os.getenv('LINES', 0)))
|
height=int(os.getenv('LINES', 0)))
|
||||||
shcmd, prompt, success_key = utils.make_sudo_cmd(sudo_user, executable, cmd)
|
if self.runner.sudo or sudoable:
|
||||||
|
shcmd, prompt, success_key = utils.make_sudo_cmd(sudo_user, executable, cmd)
|
||||||
|
elif self.runner.su or su:
|
||||||
|
shcmd, prompt, success_key = utils.make_su_cmd(su_user, executable, cmd)
|
||||||
vvv("EXEC %s" % shcmd, host=self.host)
|
vvv("EXEC %s" % shcmd, host=self.host)
|
||||||
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:
|
||||||
|
@ -223,7 +226,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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue