關於ansbile工具的shell、command、script、raw模塊的區別和使用場景


command模塊 [執行遠程命令]

 

[root@node1 ansible]# ansible testservers -m command -a 'uname -n'

 

script模塊 [在遠程主機執行主控端的shell/python腳本 ]  (使用相對路徑)

 

[root@node1 ansible]# ansible testservers -m script -a '/etc/ansible/test.sh

 

 shell模塊 [執行遠程主機的shell/python腳本]

 

[root@node1 ansible]# ansible testservers -m shell -a 'bash /root/test.sh'

 

 raw模塊 [類似於command模塊、支持管道傳遞]

 

[root@node1 ansible]# ansible testservers -m raw -a "ifconfig eth0 |sed -n 2p |awk '{print \$2}' |awk -F: '{print \$2}'"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM