Typically, the shell, command, or script modules are used to invoke a command on a managed node (e.g. target systems). /usr/bin/python needs to exist on the managed node to use these modules. If Python does not exist, the raw module can be used instead.
The ansible-doc shell command can be used to show the Ansible documention on the shell module.
In this example, the ps command will be invoked on the managed nodes.
- name: ps command shell: "ps"
The following should be produced.
TASK [ps command] changed: [server1.example.com]
By default, no stdout is printed. The register parameter can be used to print output to the console.
non-zero return code
If non-zero return code is being displayed in the output of the play, refer to our article on resolving non-zero return code.
Become (root, sudo)
If you do not have permission to issue a certain shell command, permission denied will be returned. To resolve this, the become module can be used to become root.
Certain arguments can be used with the shell command. In this example, the chdir (change directory) argument is used to perform the shell command from a particular directory.
- name: ps command shell: "ls" arg: chdir: /root
connection module / delegate_to module