ansible 'raw'、'shell' 和 'command' 之间有什么区别? [英] Whats the difference between ansible 'raw', 'shell' and 'command'?
问题描述
ansible playbook 中的 raw
、shell
和 command
有什么区别?什么时候使用哪个?
What is the difference between raw
, shell
and command
in the ansible playbook? And when to use which?
推荐答案
command:在目标主机上执行远程命令,在其他 playbook 任务的同一个 shell 中.
它可用于启动脚本 (.sh) 或执行简单命令.例如:
command: executes a remote command on 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:在目标主机上执行远程命令,打开一个新外壳 (/bin/sh).
如果您想执行更复杂的命令,例如与管道连接的命令,则可以使用它.例如:
shell: executes a remote command on 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:执行缺少解释器的低级命令目标主机,一个常见的用例是安装 python.不应在所有其他情况下使用此模块(建议使用 command 和 shell)
raw: executes low-level commands where interpreter is missing on 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)
这篇关于ansible 'raw'、'shell' 和 'command' 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!