+

Search Tips   |   Advanced Search

ansible.builtin.command - Execute commands on targets

This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name command even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.


Synopsis

This module has a corresponding action plugin.


Parameters

Parameter Choices/Defaults Comments

argv

list / elements=string

Passes the command as a list rather than a string.

Use argv to avoid quoting values that would otherwise be interpreted incorrectly (for example "user name").

Only the string (free form) or the list (argv) form can be provided, not both. One or the other must be provided.

chdir

path

Change into this directory before running the command.

cmd

string

The command to run.

creates

path

A filename or (since 2.0) glob pattern. If a matching file already exists, this step won't be run.

free_form

string

The command module takes a free form string as a command to run.

There is no actual parameter named 'free form'.

removes

path

A filename or (since 2.0) glob pattern. If a matching file exists, this step will be run.

stdin

string

Set the stdin of the command directly to the specified value.

stdin_add_newline

boolean

  • no

  • yes ←

If set to yes, append a newline to stdin data.

strip_empty_ends

boolean

  • no

  • yes ←

Strip empty lines from the end of stdout/stderr in result.

warn

boolean

  • no

  • yes ←

Enable or disable task warnings.



Notes


See Also


See also

ansible.builtin.raw

The official documentation on the ansible.builtin.raw module.

ansible.builtin.script

The official documentation on the ansible.builtin.script module.

ansible.builtin.shell

The official documentation on the ansible.builtin.shell module.

ansible.windows.win_command

The official documentation on the ansible.windows.win_command module.


Examples


Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description

cmd

list / elements=string

always

The command executed by the task

Sample:

['echo', 'hello']

delta

string

always

The command execution delta time

Sample:

0:00:00.001529

end

string

always

The command execution end time

Sample:

2017-09-29 22:03:48.084657

msg

boolean

always

changed

Sample:

True

rc

integer

always

The command return code (0 means success)

start

string

always

The command execution start time

Sample:

2017-09-29 22:03:48.083128

stderr

string

always

The command standard error

Sample:

ls cannot access foo: No such file or directory

stderr_lines

list / elements=string

always

The command standard error split in lines

Sample:

[{"u'ls cannot access foo": "No such file or directory'"}, "u'ls …'"]

stdout

string

always

The command standard output

Sample:

Clustering node [email protected] with [email protected]

stdout_lines

list / elements=string

always

The command standard output split in lines

Sample:

["u'Clustering node [email protected] with [email protected] …'"]




Authors