关于ansbile工具的shell、command、script、raw模块的区别和使用场景

    之前一直误解为shell和command一样是执行远程命令的,最近看了一下官方帮助文档才发现,犯了低级错误,其实每个模块都有自己的应用常用;简单说明一下ansible几个常用模块的区别,以便自己总结。

  1.模块命令详细信息查询

ansible-doc 模块名称

  2.command模块 [执行远程命令]

ansible client -m command -a "uname -n" -s

  3.script模块 [在远程主机执行主控端的shell/python脚本]

ansible client -m script -a "/soft/ntpdate.py" -s

  4.shell模块 [执行远程主机的shell/python脚本]

ansible client -m shell -a "/soft/file.py" -s

  5.raw模块 [类似于command模块、支持管道传递]

ansible client -m raw -a "ifconfig eth0|sed -n 2p|awk '{print \$2}'" -s

 

你可能感兴趣的:(ansbile模块)