Skip to main content

shell

shell module

Execute shell commands on the target host. Unlike the command module, the shell module runs commands through a shell (/bin/sh), which allows for shell features like pipes, redirects, and variable expansion.

Examples

- name: Run a simple command
shell: ls -la /tmp

- name: Use shell features like pipes
shell: ps aux | grep nginx

- name: Command with environment variables
shell: echo $HOME

- name: Multi-line command
shell: |
if [ -f /etc/passwd ]; then
echo "File exists"
fi

Warning: Be careful with shell injection when using variables in shell commands. Always validate and sanitize input.

Module Capabilities

  • Has Revert: false
  • Provides Variables: None

Inputs

ParameterTypeDescriptionRequiredDefaultChoices
executestringThe shell command to execute. Can use shell features like pipes, redirects, and variable expansion.false
revertstringThe shell command to execute when reverting changes made by the execute command.false

Outputs

FieldTypeDescription
commandstring
stderrstring
stderr_lines[string]
stdoutstring
stdout_lines[string]

Parameter aliases

  • cmd → execute