-
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
Open
nama1arpit
wants to merge
3
commits into
ansible:devel
Choose a base branch
from
nama1arpit:fix-interactive-cmd
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−16
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
While there are arguments in common between those modules, they're not all the same. For example,
the
win_command
module does not acceptstrip_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 usingcheck_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
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
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 whencheck_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:
Currently this results in running:
some_command -o cmd=something
With
cmd
in the list of args used bycheck_raw
, it would instead become:some_command -o
This should be discussed further before we commit to a solution.