Ansible中shell,command,raw模块的区别

本文详细介绍了Ansible中用于远程执行指令的三个模块:command、shell与raw的区别与适用场景。command模块不通过shell执行命令,shell模块则通过/bin/sh执行命令,而raw模块直接执行SSH命令,适用于特定情况,如安装老版本Python依赖或与未安装Python的设备通信。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

command shell raw 模块之间的区别

command,shell,raw模块都是ansible远程执行node服务器的一种指令模式 但是3个模块的适用还是有一定的区别

command 模块

The command module takes the command name followed by a list of space-delimited arguments. The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", and "&" will not work (use the shell module if you need these features).

注解:command模块不是调用的shell的指令,所以没有bash的环境变量,也不能使用shell的一些操作方式,其他和shell没有区别

http://docs.ansible.com/ansible/command_module.html#command

shell 模块

The shell module takes the command name followed by a list of space-delimited arguments. It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

注解:shell模块调用的/bin/sh指令执行

http://docs.ansible.com/ansible/shell_module.html

raw 模块

Executes a low-down and dirty SSH command, not going through the module subsystem. This is useful and should only be done in two cases. The first case is installing python-simplejson on older (Python 2.4 and before) hosts that need it as a dependency to run modules, since nearly all core modules require it. Another is speaking to any devices such as routers that do not have any Python installed. In any other case, using the shell or command module is much more appropriate. Arguments given to raw are run directly through the configured remote shell. Standard output, error output and return code are returned when available. There is no change handler support for this module. This module does not require python on the remote system, much like the script module.

注释:raw很多地方和shell类似,更多的地方建议使用shell和command模块。但是如果是使用老版本python,需要用到raw,又或者是客户端是路由器,因为没有安装python模块,那就需要使用raw模块了

http://docs.ansible.com/ansible/raw_module.html

转载于:https://my.oschina.net/mesopotamia/blog/490272

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值