Improve examples on parameters use with argv (#60781)
* Add example showing that when using the `argv` syntax for command module instead of the string one, we can directly provide other parameters in the "command" block, rather than using an "args" block.
This commit is contained in:
parent
a4b36b2e6a
commit
8a5adcd8e1
1 changed files with 7 additions and 4 deletions
|
@ -33,7 +33,7 @@ description:
|
||||||
options:
|
options:
|
||||||
free_form:
|
free_form:
|
||||||
description:
|
description:
|
||||||
- The command module takes a free form command to run.
|
- The command module takes a free form string as a command to run.
|
||||||
- There is no actual parameter named 'free form'.
|
- There is no actual parameter named 'free form'.
|
||||||
cmd:
|
cmd:
|
||||||
type: str
|
type: str
|
||||||
|
@ -44,8 +44,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- Passes the command as a list rather than a string.
|
- Passes the command as a list rather than a string.
|
||||||
- Use C(argv) to avoid quoting values that would otherwise be interpreted incorrectly (for example "user name").
|
- Use C(argv) to avoid quoting values that would otherwise be interpreted incorrectly (for example "user name").
|
||||||
- Only the string or the list form can be
|
- Only the string (free form) or the list (argv) form can be provided, not both. One or the other must be provided.
|
||||||
provided, not both. One or the other must be provided.
|
|
||||||
version_added: "2.6"
|
version_added: "2.6"
|
||||||
creates:
|
creates:
|
||||||
type: path
|
type: path
|
||||||
|
@ -109,9 +108,11 @@ EXAMPLES = r'''
|
||||||
command: cat /etc/motd
|
command: cat /etc/motd
|
||||||
register: mymotd
|
register: mymotd
|
||||||
|
|
||||||
- name: Run command if /path/to/database does not exist (without 'args' keyword).
|
# free-form (string) arguments, all arguments on one line
|
||||||
|
- name: Run command if /path/to/database does not exist (without 'args').
|
||||||
command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database
|
command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database
|
||||||
|
|
||||||
|
# free-form (string) arguments, some arguments on separate lines with the 'args' keyword
|
||||||
# 'args' is a task keyword, passed at the same level as the module
|
# 'args' is a task keyword, passed at the same level as the module
|
||||||
- name: Run command if /path/to/database does not exist (with 'args' keyword).
|
- name: Run command if /path/to/database does not exist (with 'args' keyword).
|
||||||
command: /usr/bin/make_database.sh db_user db_name
|
command: /usr/bin/make_database.sh db_user db_name
|
||||||
|
@ -132,6 +133,7 @@ EXAMPLES = r'''
|
||||||
chdir: somedir/
|
chdir: somedir/
|
||||||
creates: /path/to/database
|
creates: /path/to/database
|
||||||
|
|
||||||
|
# argv (list) arguments, each argument on a separate line, 'args' keyword not necessary
|
||||||
# 'argv' is a parameter, indented one level from the module
|
# 'argv' is a parameter, indented one level from the module
|
||||||
- name: Use 'argv' to send a command as a list - leave 'command' empty
|
- name: Use 'argv' to send a command as a list - leave 'command' empty
|
||||||
command:
|
command:
|
||||||
|
@ -139,6 +141,7 @@ EXAMPLES = r'''
|
||||||
- /usr/bin/make_database.sh
|
- /usr/bin/make_database.sh
|
||||||
- Username with whitespace
|
- Username with whitespace
|
||||||
- dbname with whitespace
|
- dbname with whitespace
|
||||||
|
creates: /path/to/database
|
||||||
|
|
||||||
- name: safely use templated variable to run command. Always use the quote filter to avoid injection issues.
|
- name: safely use templated variable to run command. Always use the quote filter to avoid injection issues.
|
||||||
command: cat {{ myfile|quote }}
|
command: cat {{ myfile|quote }}
|
||||||
|
|
Loading…
Reference in a new issue