# Buggy code
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
    """handler for file transfer operations"""

    if self.runner.noop_on_check(inject):
        # in check mode, always skip this module
        return ReturnData(
            conn=conn,
            comm_ok=True,
            result=dict(skipped=True, msg="check mode not supported for this module"),
        )

    tokens = shlex.split(module_args)
    source = tokens[0]
    # FIXME: error handling
    args = " ".join(tokens[1:])
    source = template.template(self.runner.basedir, source, inject)
    if "_original_file" in inject:
        source = utils.path_dwim_relative(
            inject["_original_file"], "files", source, self.runner.basedir
        )
    else:
        source = utils.path_dwim(self.runner.basedir, source)

    # transfer the file to a remote tmp location
    source = source.replace("\x00", "")  # why does this happen here?
    args = args.replace("\x00", "")  # why does this happen here?
    tmp_src = os.path.join(tmp, os.path.basename(source))
    tmp_src = tmp_src.replace("\x00", "")

    conn.put_file(source, tmp_src)

    # fix file permissions when the copy is done as a different user
    if self.runner.sudo and self.runner.sudo_user != "root":
        prepcmd = "chmod a+rx %s" % tmp_src
    else:
        prepcmd = "chmod +x %s" % tmp_src

    # add preparation steps to one ssh roundtrip executing the script
    env_string = self.runner._compute_environment_string(inject)
    module_args = prepcmd + "; " + env_string + tmp_src + " " + args

    handler = utils.plugins.action_loader.get("raw", self.runner)
    result = handler.run(conn, tmp, "raw", module_args, inject)

    # clean up after
    if tmp.find("tmp") != -1 and not C.DEFAULT_KEEP_REMOTE_FILES:
        self.runner._low_level_exec_command(
            conn, "rm -rf %s >/dev/null 2>&1" % tmp, tmp
        )

    return result


# Traceback (TypeError)
TASK: [script myscript.sh /home] **********************************************
fatal: [111.111.111.111] => Traceback (most recent call last):
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/site-packages/ansible/runner/__init__.py", line 382, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/site-packages/ansible/runner/__init__.py", line 471, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/site-packages/ansible/runner/__init__.py", line 654, in _executor_internal_inner
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/site-packages/ansible/runner/action_plugins/script.py", line 45, in run
source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir)
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/site-packages/ansible/utils/__init__.py", line 259, in path_dwim_relative
if os.path.exists(source2):
File "/Users/julien/.virtualenvs/myenv/lib/python2.6/genericpath.py", line 18, in exists
st = os.stat(path)
TypeError: stat() argument 1 must be encoded string without NULL bytes, not str

# Fixed code
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
    """handler for file transfer operations"""

    if self.runner.noop_on_check(inject):
        # in check mode, always skip this module
        return ReturnData(
            conn=conn,
            comm_ok=True,
            result=dict(skipped=True, msg="check mode not supported for this module"),
        )

    # Decode the result of shlex.split() to UTF8 to get around a bug in that's been fixed in Python 2.7 but not Python 2.6.
    # See: http://bugs.python.org/issue6988
    tokens = shlex.split(module_args.encode("utf8"))
    tokens = [s.decode("utf8") for s in tokens]

    source = tokens[0]
    # FIXME: error handling
    args = " ".join(tokens[1:])
    source = template.template(self.runner.basedir, source, inject)
    if "_original_file" in inject:
        source = utils.path_dwim_relative(
            inject["_original_file"], "files", source, self.runner.basedir
        )
    else:
        source = utils.path_dwim(self.runner.basedir, source)

    # transfer the file to a remote tmp location
    source = source.replace("\x00", "")  # why does this happen here?
    args = args.replace("\x00", "")  # why does this happen here?
    tmp_src = os.path.join(tmp, os.path.basename(source))
    tmp_src = tmp_src.replace("\x00", "")

    conn.put_file(source, tmp_src)

    # fix file permissions when the copy is done as a different user
    if self.runner.sudo and self.runner.sudo_user != "root":
        prepcmd = "chmod a+rx %s" % tmp_src
    else:
        prepcmd = "chmod +x %s" % tmp_src

    # add preparation steps to one ssh roundtrip executing the script
    env_string = self.runner._compute_environment_string(inject)
    module_args = prepcmd + "; " + env_string + tmp_src + " " + args

    handler = utils.plugins.action_loader.get("raw", self.runner)
    result = handler.run(conn, tmp, "raw", module_args, inject)

    # clean up after
    if tmp.find("tmp") != -1 and not C.DEFAULT_KEEP_REMOTE_FILES:
        self.runner._low_level_exec_command(
            conn, "rm -rf %s >/dev/null 2>&1" % tmp, tmp
        )

    return result