在Ansible中,'shell'和'command'都是用来在远程主机上执行命令的模块。但是它们之间有一些区别。
示例:
- name: 使用shell模块执行命令
shell: ls -l /path/to/directory
示例:
- name: 使用command模块执行命令
command: ls -l /path/to/directory
需要注意的是,由于'command'模块不使用shell,所以某些特殊的命令可能无法正常执行。在这种情况下,可以使用'raw'模块执行原始命令,但要谨慎使用。
示例:
- name: 使用raw模块执行原始命令
raw: ls -l /path/to/directory
以上是Ansible中'shell'和'command'模块的区别以及相应的解决方法。根据你的需求选择适合的模块来执行命令。