關於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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章