ansible: disable script interpreter processing for new-style

Re: #199
pull/206/head
David Wilson 7 years ago
parent 1909fb43f5
commit 8c3b1fcf15

@ -208,28 +208,26 @@ class ScriptPlanner(BinaryPlanner):
Common functionality for script module planners -- handle interpreter
detection and rewrite.
"""
def _rewrite_interpreter(self, invocation, interpreter):
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):
def _get_interpreter(self, invocation):
interpreter, arg = parse_script_interpreter(invocation.module_source)
if interpreter is None:
raise ansible.errors.AnsibleError(NO_INTERPRETER_MSG % (
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(
invocation=invocation,
interpreter_arg=arg,
interpreter=self._rewrite_interpreter(
interpreter=interpreter,
invocation=invocation
),
interpreter=interpreter,
**kwargs
)
@ -301,6 +299,9 @@ class NewStylePlanner(ScriptPlanner):
"""
runner_name = 'NewStyleRunner'
def _get_interpreter(self, invocation):
return None, None
def get_should_fork(self, invocation):
"""
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_want_json_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_want_json_module.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