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
Parameter | Type | Description | Required | Default | Choices |
---|---|---|---|---|---|
execute | string | The shell command to execute. Can use shell features like pipes, redirects, and variable expansion. | false | ||
revert | string | The shell command to execute when reverting changes made by the execute command. | false |
Outputs
Field | Type | Description |
---|---|---|
command | string | |
stderr | string | |
stderr_lines | [string] | |
stdout | string | |
stdout_lines | [string] |
Parameter aliases
- cmd → execute