issue #195: handle non-ASCII scripts in runner.py.

This commit is contained in:
David Wilson 2018-04-20 20:47:07 +01:00
parent 85e1f5f515
commit e7831a801f
4 changed files with 34 additions and 2 deletions

View File

@ -61,6 +61,15 @@ ansible.module_utils.basic._ANSIBLE_ARGS = '{}'
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
def utf8(s):
"""
Coerce an object to bytes if it is Unicode.
"""
if isinstance(s, unicode):
s = s.encode('utf-8')
return s
def reopen_readonly(fp): def reopen_readonly(fp):
""" """
Replace the file descriptor belonging to the file object `fp` with one Replace the file descriptor belonging to the file object `fp` with one
@ -329,9 +338,9 @@ class ScriptRunner(ProgramRunner):
if not self.interpreter: if not self.interpreter:
return s return s
shebang = '#!' + self.interpreter shebang = '#!' + utf8(self.interpreter)
if self.interpreter_arg: if self.interpreter_arg:
shebang += ' ' + self.interpreter_arg shebang += ' ' + utf8(self.interpreter_arg)
new = [shebang] new = [shebang]
if os.path.basename(self.interpreter).startswith('python'): if os.path.basename(self.interpreter).startswith('python'):

View File

@ -9,5 +9,6 @@
- import_playbook: custom_python_json_args_module.yml - import_playbook: custom_python_json_args_module.yml
- import_playbook: custom_python_new_style_module.yml - import_playbook: custom_python_new_style_module.yml
- import_playbook: custom_python_want_json_module.yml - import_playbook: custom_python_want_json_module.yml
- import_playbook: custom_script_interpreter.yml
- import_playbook: forking_behaviour.yml - import_playbook: forking_behaviour.yml
- import_playbook: remote_tmp.yml - import_playbook: remote_tmp.yml

View File

@ -0,0 +1,18 @@
- name: integration/runner/custom_script_interpreter.yml
hosts: all
any_errors_fatal: true
tasks:
- custom_bash_old_style_module:
foo: true
with_sequence: start=1 end={{end|default(1)}}
register: out
vars:
ansible_bash_interpreter: /bin/bash
- assert:
that: |
(not out.changed) and
(not out.results[0].changed) and
out.results[0].msg == 'Here is my input'

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
# I am an Ansible old-style module. # I am an Ansible old-style module.
# This line is to encourage a UnicodeDecodeError in
# integration/runner/custom_script_interpreter.yml
# see https://github.com/dw/mitogen/issues/195
# £££ 
INPUT=$1 INPUT=$1
[ ! -r "$INPUT" ] && { [ ! -r "$INPUT" ] && {