Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between ansible 'raw', 'shell' and 'command'?

Tags:

ansible

What is the difference between raw, shell and command in the ansible playbook? And when to use which?

like image 525
Rene B. Avatar asked Feb 19 '26 04:02

Rene B.


1 Answers

command: executes a remote command on the target host, in the same shell of other playbook's tasks.
It can be used for launch scripts (.sh) or for execute simple commands. For example:

- name: Cat a file
  command: cat somefile.txt

- name: Execute a script
  command: somescript.sh param1 param2

shell: executes a remote command on the target host, opening a new shell (/bin/sh).
It can be used if you want to execute more complex commands, for example, commands concatenated with pipes. For example:

- name: Look for something in a file
  shell: cat somefile.txt | grep something

raw: executes low-level commands where the interpreter is missing on the target host, a common use case is for installing python. This module should not be used in all other cases (where command and shell are suggested)

like image 196
TinaC Avatar answered Feb 22 '26 04:02

TinaC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!