Arpit Nama 2 weeks ago committed by GitHub
commit 383dfc7028
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- shell module - parameter-oriented invocation using 'cmd' was silently failing. Fix now adds 'cmd' argument in shell module and creates centralized list of options for usage in `splitter.py` (https://github.com/ansible/ansible/issues/73005).

@ -0,0 +1,25 @@
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
def get_command_args():
'''
The function for a centralised list for retrieval of shell module options
'''
return dict(
_raw_params=dict(),
_uses_shell=dict(type='bool', default=False),
argv=dict(type='list', elements='str'),
chdir=dict(type='path'),
executable=dict(),
expand_argument_vars=dict(type='bool', default=True),
creates=dict(type='path'),
removes=dict(type='path'),
# The default for this really comes from the action plugin
stdin=dict(required=False),
stdin_add_newline=dict(type='bool', default=True),
strip_empty_ends=dict(type='bool', default=True),
cmd=dict(),
)

@ -239,6 +239,7 @@ import shlex
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native, to_bytes, to_text
from ansible.module_utils.common.collections import is_iterable
from ansible.module_utils.shell import get_command_args
def main():
@ -247,20 +248,7 @@ def main():
# hence don't copy this one if you are looking to build others!
# NOTE: ensure splitter.py is kept in sync for exceptions
module = AnsibleModule(
argument_spec=dict(
_raw_params=dict(),
_uses_shell=dict(type='bool', default=False),
argv=dict(type='list', elements='str'),
chdir=dict(type='path'),
executable=dict(),
expand_argument_vars=dict(type='bool', default=True),
creates=dict(type='path'),
removes=dict(type='path'),
# The default for this really comes from the action plugin
stdin=dict(required=False),
stdin_add_newline=dict(type='bool', default=True),
strip_empty_ends=dict(type='bool', default=True),
),
argument_spec=get_command_args(),
supports_check_mode=True,
)
shell = module.params['_uses_shell']

@ -22,6 +22,7 @@ import re
from ansible.errors import AnsibleParserError
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.shell import get_command_args
from ansible.parsing.quoting import unquote
@ -77,8 +78,7 @@ def parse_kv(args, check_raw=False):
k = x[:pos]
v = x[pos + 1:]
# FIXME: make the retrieval of this list of shell/command options a function, so the list is centralized
if check_raw and k not in ('creates', 'removes', 'chdir', 'executable', 'warn', 'stdin', 'stdin_add_newline', 'strip_empty_ends'):
if check_raw and k not in get_command_args():
raw_params.append(orig_x)
else:
options[k.strip()] = unquote(v.strip())

@ -480,6 +480,18 @@
- shell_result9 is failed or
shell_result9 is changed
- name: execute a shell command with parameter-oriented invocation using "cmd"
shell: 'cmd="echo test"'
register: shell_result10
- name: Assert the shell with parameter-oriented invocation ran as expected
assert:
that:
- shell_result10 is changed
- shell_result10.rc == 0
- shell_result10.cmd == "echo test"
- shell_result10.stdout == "test"
- name: remove the previously created file
file:
path: "{{ remote_tmp_dir_test }}/afile.txt"

Loading…
Cancel
Save