Merge pull request #198 from dw/dmw

issue #195: handle non-ASCII scripts in runner.py.
pull/205/head
dw 7 years ago committed by GitHub
commit 8f54fcfca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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'):

@ -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

@ -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'

@ -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" ] && {

Loading…
Cancel
Save