Fix problems with non-ascii values passed as part of the command to connection plugins

@drybjed discovered this with non-ascii environment variables and
command line arguments to script and raw module.
This commit is contained in:
Toshio Kuratomi 2016-01-04 19:23:12 -08:00
parent 8d57ffd16b
commit c0a8cd950b
10 changed files with 97 additions and 13 deletions

View file

@ -25,10 +25,13 @@ import select
import fcntl
import getpass
from ansible.compat.six import text_type, binary_type
import ansible.constants as C
from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.plugins.connection import ConnectionBase
from ansible.utils.unicode import to_bytes
try:
from __main__ import display
@ -69,9 +72,15 @@ class Connection(ConnectionBase):
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else None
display.vvv("{0} EXEC {1}".format(self._play_context.remote_addr, cmd))
display.vvv(u"{0} EXEC {1}".format(self._play_context.remote_addr, cmd))
# FIXME: cwd= needs to be set to the basedir of the playbook
display.debug("opening command with Popen()")
if isinstance(cmd, (text_type, binary_type)):
cmd = to_bytes(cmd)
else:
cmd = map(to_bytes, cmd)
p = subprocess.Popen(
cmd,
shell=isinstance(cmd, basestring),