Merge pull request #206 from dw/dmw

ansible: disable script interpreter processing for new-style
pull/209/head
dw 7 years ago committed by GitHub
commit daffa14b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -208,28 +208,26 @@ class ScriptPlanner(BinaryPlanner):
Common functionality for script module planners -- handle interpreter Common functionality for script module planners -- handle interpreter
detection and rewrite. detection and rewrite.
""" """
def _rewrite_interpreter(self, invocation, interpreter): def _get_interpreter(self, invocation):
key = u'ansible_%s_interpreter' % os.path.basename(interpreter).strip()
try:
template = invocation.task_vars[key].strip()
return invocation.templar.template(template)
except KeyError:
return interpreter
def plan(self, invocation, **kwargs):
interpreter, arg = parse_script_interpreter(invocation.module_source) interpreter, arg = parse_script_interpreter(invocation.module_source)
if interpreter is None: if interpreter is None:
raise ansible.errors.AnsibleError(NO_INTERPRETER_MSG % ( raise ansible.errors.AnsibleError(NO_INTERPRETER_MSG % (
invocation.module_name, invocation.module_name,
)) ))
key = u'ansible_%s_interpreter' % os.path.basename(interpreter).strip()
try:
template = invocation.task_vars[key].strip()
return invocation.templar.template(template), arg
except KeyError:
return interpreter, arg
def plan(self, invocation, **kwargs):
interpreter, arg = self._get_interpreter(invocation)
return super(ScriptPlanner, self).plan( return super(ScriptPlanner, self).plan(
invocation=invocation, invocation=invocation,
interpreter_arg=arg, interpreter_arg=arg,
interpreter=self._rewrite_interpreter( interpreter=interpreter,
interpreter=interpreter,
invocation=invocation
),
**kwargs **kwargs
) )
@ -301,6 +299,9 @@ class NewStylePlanner(ScriptPlanner):
""" """
runner_name = 'NewStyleRunner' runner_name = 'NewStyleRunner'
def _get_interpreter(self, invocation):
return None, None
def get_should_fork(self, invocation): def get_should_fork(self, invocation):
""" """
In addition to asynchronous tasks, new-style modules should be forked In addition to asynchronous tasks, new-style modules should be forked

@ -7,6 +7,7 @@
- import_playbook: custom_perl_json_args_module.yml - import_playbook: custom_perl_json_args_module.yml
- import_playbook: custom_perl_want_json_module.yml - import_playbook: custom_perl_want_json_module.yml
- import_playbook: custom_python_json_args_module.yml - import_playbook: custom_python_json_args_module.yml
- import_playbook: custom_python_new_style_missing_interpreter.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: custom_script_interpreter.yml

@ -0,0 +1,17 @@
- name: integration/runner__custom_python_new_style_module.yml
hosts: all
any_errors_fatal: true
tasks:
- custom_python_new_style_missing_interpreter:
foo: true
with_sequence: start=1 end={{end|default(1)}}
register: out
- assert:
that: |
(not out.changed) and
(not out.results[0].changed) and
out.results[0].input[0].ANSIBLE_MODULE_ARGS.foo and
out.results[0].msg == 'Here is my input'

@ -0,0 +1,26 @@
# I am an Ansible new-style Python module, but I lack an interpreter.
import json
import sys
# This is the magic marker Ansible looks for:
# from ansible.module_utils.
def usage():
sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],))
sys.exit(1)
# Also must slurp in our own source code, to verify the encoding string was
# added.
with open(sys.argv[0]) as fp:
me = fp.read()
input_json = sys.stdin.read()
print "{"
print " \"changed\": false,"
print " \"msg\": \"Here is my input\","
print " \"source\": [%s]," % (json.dumps(me),)
print " \"input\": [%s]" % (input_json,)
print "}"
Loading…
Cancel
Save