-
Notifications
You must be signed in to change notification settings - Fork 24k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a function for the centralised list of shell/command options #81558
base: devel
Are you sure you want to change the base?
Conversation
Added the changelog fragment |
This comment was marked as resolved.
This comment was marked as resolved.
@@ -79,8 +80,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(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the current list of key-value arguments is out-of-date, I don't think that's a good reason to move them into module_utils. The main reason is that the list of valid arguments varies by module. There are currently 6 different modules that make use of check_raw
:
ansible/lib/ansible/constants.py
Lines 116 to 117 in 116948c
MODULE_REQUIRE_ARGS = tuple(add_internal_fqcns(('command', 'win_command', 'ansible.windows.win_command', 'shell', 'win_shell', | |
'ansible.windows.win_shell', 'raw', 'script'))) |
While there are arguments in common between those modules, they're not all the same. For example,
the win_command
module does not accept strip_empty_ends
.
It seems like we'd be better off checking the actual list of arguments accepted by the module we're parsing for, and use those when calling parse_kv
, instead of using check_raw
to activate a hard-coded list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the approach in this PR was suggested by @sivel in #73005 (comment) -- although that seems to have been based on a ~9 year old code comment that predates the split to collections:
ansible/lib/ansible/parsing/splitter.py
Lines 90 to 91 in 29aea9f
# FIXME: make the retrieval of this list of shell/command | |
# options a function, so the list is centralized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the concern and I would need some more guidance to resolve this as I am not very familiar with the codebase. I can see that parse_kv
is used in a few places. Should I try to get the actual list of arguments accepted by the module here?
ansible/lib/ansible/cli/console.py
Lines 204 to 206 in 29aea9f
try: | |
check_raw = module in C._ACTION_ALLOWS_RAW_ARGS | |
task = dict(action=dict(module=module, args=parse_kv(module_args, check_raw=check_raw)), timeout=self.task_timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there isn't a good way to get the supported action/module args from the action name while parsing args.
Rather than implementing that (a non-trivial task), one option would be to add cmd
to the existing hard-coded list used by the splitter when check_raw
is enabled.
While that would allow resolving #73005, it would also have the unwanted affect of changing how the raw
action is handled.
For example, a playbook with a task such as the following would be affected:
- raw: some_command -o cmd=something
Currently this results in running: some_command -o cmd=something
With cmd
in the list of args used by check_raw
, it would instead become: some_command -o
This should be discussed further before we commit to a solution.
Some planned features may make this more generically possible in the not-too-distant future. |
depends on #79720 |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
SUMMARY
Fixes #73005
This PR
cmd
argument to theshell
/command
optionsshell
module options to a centralized function for usage insplitter.py
ISSUE TYPE
ADDITIONAL INFORMATION
Integration testing:
Sanity testing: