The shell module can be used to run a shell command on the target servers. In this example, the ps command will be invoked on the target servers.
- 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 module 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.
Sudo / Become
If you want to perform a task on target server(s) that requires the use of sudo, refer to our article on using the become module.
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