summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/connection/zone.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/connection/zone.py')
-rw-r--r--lib/ansible/plugins/connection/zone.py35
1 files changed, 11 insertions, 24 deletions
diff --git a/lib/ansible/plugins/connection/zone.py b/lib/ansible/plugins/connection/zone.py
index f0001d3c9e..b65c80b73f 100644
--- a/lib/ansible/plugins/connection/zone.py
+++ b/lib/ansible/plugins/connection/zone.py
@@ -31,6 +31,7 @@ import traceback
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.plugins.connection import ConnectionBase
+from ansible.utils import to_bytes
try:
from __main__ import display
@@ -45,13 +46,8 @@ class Connection(ConnectionBase):
''' Local zone based connections '''
transport = 'zone'
- # Pipelining may work. Someone needs to test by setting this to True and
- # having pipelining=True in their ansible.cfg
- 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()
+ has_pipelining = True
+ become_methods = frozenset(C.BECOME_METHODS).difference(('su',))
def __init__(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
@@ -61,8 +57,8 @@ class Connection(ConnectionBase):
if os.geteuid() != 0:
raise AnsibleError("zone connection requires running as root")
- self.zoneadm_cmd = self._search_executable('zoneadm')
- self.zlogin_cmd = self._search_executable('zlogin')
+ self.zoneadm_cmd = to_bytes(self._search_executable('zoneadm'))
+ self.zlogin_cmd = to_bytes(self._search_executable('zlogin'))
if self.zone not in self.list_zones():
raise AnsibleError("incorrect zone name %s" % self.zone)
@@ -91,7 +87,7 @@ class Connection(ConnectionBase):
def get_zone_path(self):
#solaris10vm# zoneadm -z cswbuild list -p
#-:cswbuild:installed:/zones/cswbuild:479f3c4b-d0c6-e97b-cd04-fd58f2c0238e:native:shared
- process = subprocess.Popen([self.zoneadm_cmd, '-z', self.zone, 'list', '-p'],
+ process = subprocess.Popen([self.zoneadm_cmd, '-z', to_bytes(self.zone), 'list', '-p'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -114,13 +110,11 @@ class Connection(ConnectionBase):
compared to exec_command() it looses some niceties like being able to
return the process's exit code immediately.
'''
- # FIXME: previous code took pains not to invoke /bin/sh and left out
- # -c. Not sure why as cmd could contain shell metachars (like
- # cmd = "mkdir -p $HOME/pathname && echo $HOME/pathname") which
- # probably wouldn't work without a shell. Get someone to test that
- # 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]
+ # Note: zlogin invokes a shell (just like ssh does) so we do not pass
+ # this through /bin/sh -c here. Instead it goes through the shell
+ # that zlogin selects.
+ local_cmd = [self.zlogin_cmd, self.zone, cmd]
+ local_cmd = map(to_bytes, local_cmd)
display.vvv("EXEC %s" % (local_cmd), host=self.zone)
p = subprocess.Popen(local_cmd, shell=False, stdin=stdin,
@@ -132,13 +126,6 @@ class Connection(ConnectionBase):
''' run a command on the zone '''
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)
stdout, stderr = p.communicate(in_data)