首页 > 解决方案 > ansible'raw','shell'和'command'有什么区别?

问题描述

raw和in the ansible playbook 有什么shell区别?command什么时候用哪个?

标签: ansible

解决方案


command:在目标主机上执行远程命令,在其他 playbook 任务的同一 shell 中。
它可用于启动脚本 (.sh) 或执行简单命令。例如:

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

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

shell:在目标主机上执行远程命令,打开一个新的 shell (/bin/sh)。
如果您想执行更复杂的命令,例如与管道连接的命令,可以使用它。例如:

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

raw:在目标主机上缺少解释器的情况下执行低级命令,一个常见的用例是安装 python。此模块不应在所有其他情况下使用(建议使用命令和 shell)


推荐阅读