Added executable parameter to the script module (#36969)

* Added interpreter parameter to the script module

* Let required and default parameters get documented implicitly for binary parameter

* Renamed interpreter parameter to executable
pull/40739/head
tranceitionalMynd 7 years ago committed by Adam Miller
parent 43ca9d1548
commit 04e3c964fb

@ -40,6 +40,10 @@ options:
description:
- cd into this directory on the remote node before running the script
version_added: "2.4"
executable:
description:
- Name or path of a executable to invoke the script with
version_added: "2.6"
notes:
- It is usually preferable to write Ansible modules than pushing scripts. Convert your script to an Ansible module for bonus points!
- The ssh connection plugin will force pseudo-tty allocation via -tt when scripts are executed. pseudo-ttys do not have a stderr channel and all
@ -66,4 +70,14 @@ EXAMPLES = '''
- script: /some/local/remove_file.sh --some-arguments 1234
args:
removes: /the/removed/file.txt
# Run a script using a executable in a non-system path
- script: /some/local/script
args:
executable: /some/remote/executable
# Run a script using a executable in a system path
- script: /some/local/script.py
args:
executable: python3
'''

@ -79,6 +79,9 @@ class ActionModule(ActionBase):
parts = [to_text(s, errors='surrogate_or_strict') for s in shlex.split(raw_params.strip())]
source = parts[0]
# Support executable paths and files with spaces in the name.
executable = to_native(self._task.args.get('executable', ''), errors='surrogate_or_strict')
try:
source = self._loader.get_real_file(self._find_needle('files', source), decrypt=self._task.args.get('decrypt', True))
except AnsibleError as e:
@ -109,7 +112,11 @@ class ActionModule(ActionBase):
# add preparation steps to one ssh roundtrip executing the script
env_dict = dict()
env_string = self._compute_environment_string(env_dict)
script_cmd = ' '.join([env_string, target_command])
if executable:
script_cmd = ' '.join([env_string, executable, target_command])
else:
script_cmd = ' '.join([env_string, target_command])
if self._play_context.check_mode:
raise _AnsibleActionDone()

@ -0,0 +1,3 @@
import sys
sys.stdout.write("Script with shebang omitted")

@ -221,3 +221,21 @@
that:
- _check_mode_test3 is skipped
- '_check_mode_test3.msg == "{{ output_dir_test | expanduser }}/afile2.txt does not exist, matching removes option"'
# executable
- name: Run script with shebang omitted
script: no_shebang.py
args:
executable: python
register: _shebang_omitted_test
tags:
- noshebang
- name: Assert that script with shebang omitted succeeded
assert:
that:
- _shebang_omitted_test is success
- _shebang_omitted_test.stdout == 'Script with shebang omitted'
tags:
- noshebang

Loading…
Cancel
Save