Repository navigation
Conversation
The note in the ad hoc guide says that "shell variables will always
work" with the command module. The command module does not use a shell.
It expands environment variables itself with os.path.expandvars on the
managed node, controlled by the expand_argument_vars option. Variables
that are not set stay in the argument unchanged, and shell-only syntax
such as $$ or ${VAR:-default} is passed literally.
Reword the note to describe this and point to expand_argument_vars.
Assisted-by: Claude Opus 5.5
Signed-off-by: YoungjuKim <[email protected]>
Contributor
|
Thanks for your Ansible docs contribution! We talk about Ansible documentation on Matrix at #docs:ansible.im if you ever want to join us and chat about the docs! We meet on Matrix every Tuesday. See the Ansible calendar for meeting details. We welcome additions to our weekly agenda items too. You can add the |
This branch was previously deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SUMMARY
The note in "Introduction to ad hoc commands" says:
The part in parentheses is not accurate. The command module does not run a shell.
AnsibleModule.run_commandexpands the arguments itself withos.path.expandvarsandos.path.expanduser(module_utils/basic.py), and since ansible-core 2.16 this is controlled by the module optionexpand_argument_vars(defaulttrue). The module documentation already describes this: "environment variables are resolved via Python, not shell, seeexpand_argument_varsand are left unchanged if not matched."So environment variables such as
$HOMEwork, but:$NAME(a shell would replace it with an empty string);$$,$RANDOMor${VAR:-default}are passed to the command literally.This PR rewords the note to say this and points to
expand_argument_vars.ISSUE TYPE
COMPONENT NAME
docs/docsite/rst/command_guide/intro_adhoc.rst
ADDITIONAL INFORMATION
Checked with ansible-core 2.16.3 (Ubuntu 24.04 package) and ansible-core 2.21.5 (run from the
v2.21.5tag), Python 3.12, against localhost. Both versions give the same output:And in a playbook with ansible-core 2.21.5:
This change was drafted with AI assistance and reviewed by me.
🤖 Generated with Claude Code