ansible: prevent Unicode strings leaking into sys.argv

The module name comes from YAML via Jinja2.. it's always Unicode. Mixing
it into a temporary directory name produces a Unicode tempdir name,
which ends up in sys.argv via TemporaryArgv.
This commit is contained in:
David Wilson 2018-04-21 20:09:38 +01:00
parent 0795b7dccc
commit 2f02b5c0b1
3 changed files with 12 additions and 2 deletions

View File

@ -99,8 +99,8 @@ class Runner(object):
if raw_params is not None:
args['_raw_params'] = raw_params
self.module = module
self.remote_tmp = os.path.expanduser(remote_tmp)
self.module = utf8(module)
self.remote_tmp = utf8(os.path.expanduser(remote_tmp))
self.service_context = service_context
self.emulate_tty = emulate_tty
self.raw_params = raw_params

View File

@ -13,3 +13,12 @@
(not out.results[0].changed) and
out.results[0].input[0].ANSIBLE_MODULE_ARGS.foo and
out.results[0].msg == 'Here is my input'
# Verify sys.argv is not Unicode.
- custom_python_detect_environment:
register: out
- assert:
that:
- out.argv_types == ["<type 'str'>"]

View File

@ -14,6 +14,7 @@ def main():
module = AnsibleModule(argument_spec={})
module.exit_json(
argv=sys.argv,
argv_types=[str(type(s)) for s in sys.argv],
env=dict(os.environ),
cwd=os.getcwd(),
python_path=sys.path,