zone connection plugin bugfixes and pipelining and sudo become methods enabled!

Thanks to peinheber for helping test and debug this!
This commit is contained in:
Toshio Kuratomi 2015-11-16 10:37:24 -08:00
parent db27541a0e
commit fc7e2912f2

View file

@ -45,13 +45,8 @@ class Connection(ConnectionBase):
''' Local zone based connections ''' ''' Local zone based connections '''
transport = 'zone' transport = 'zone'
# Pipelining may work. Someone needs to test by setting this to True and has_pipelining = True
# having pipelining=True in their ansible.cfg become_methods = frozenset(C.BECOME_METHODS).difference(('su',))
has_pipelining = False
# Some become_methods may work in v2 (sudo works for other chroot-based
# plugins while su seems to be failing). If some work, check chroot.py to
# see how to disable just some methods.
become_methods = frozenset()
def __init__(self, play_context, new_stdin, *args, **kwargs): def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
@ -114,13 +109,10 @@ class Connection(ConnectionBase):
compared to exec_command() it looses some niceties like being able to compared to exec_command() it looses some niceties like being able to
return the process's exit code immediately. return the process's exit code immediately.
''' '''
# FIXME: previous code took pains not to invoke /bin/sh and left out # Note: zlogin invokes a shell (just like ssh does) so we do not pass
# -c. Not sure why as cmd could contain shell metachars (like # this through /bin/sh -c here. Instead it goes through the shell
# cmd = "mkdir -p $HOME/pathname && echo $HOME/pathname") which # that zlogin selects.
# probably wouldn't work without a shell. Get someone to test that local_cmd = [self.zlogin_cmd, self.zone, cmd]
# this connection plugin works and then we can remove this note
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh'
local_cmd = [self.zlogin_cmd, self.zone, executable, '-c', cmd]
display.vvv("EXEC %s" % (local_cmd), host=self.zone) display.vvv("EXEC %s" % (local_cmd), host=self.zone)
p = subprocess.Popen(local_cmd, shell=False, stdin=stdin, p = subprocess.Popen(local_cmd, shell=False, stdin=stdin,
@ -132,13 +124,6 @@ class Connection(ConnectionBase):
''' run a command on the zone ''' ''' run a command on the zone '''
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
# TODO: Check whether we can send the command to stdin via
# p.communicate(in_data)
# If we can, then we can change this plugin to has_pipelining=True and
# remove the error if in_data is given.
if in_data:
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
p = self._buffered_exec_command(cmd) p = self._buffered_exec_command(cmd)
stdout, stderr = p.communicate(in_data) stdout, stderr = p.communicate(in_data)