ansible 小技巧

來源:本站原創 Linux 超過407 views圍觀 0條評論

ansible 常用模塊之command/shell/raw

是否支持管道

module    是否支持管道
command    不支持管道
shell    支持管道——–
raw    支持管道  ——–

使用方法

[[email protected] ~]# ansible localhost -m command -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff

[[email protected] ~]# ansible localhost -m shell -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff

[[email protected] ~]# ansible localhost -m raw -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff

直接執行某個文件

[[email protected] ~]# ansible host32 -m command -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff

[[email protected] ~]# ansible host32 -m raw -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff

[[email protected] ~]# ansible host32 -m shell -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff

 

[[email protected]_master roles]# ansible all -m shell -a ‘systemctl status iptables  |grep Active’
192.168.142.102 | SUCCESS | rc=0 >>
   Active: active (exited) since Wed 2018-02-28 11:29:23 CST; 33min ago

192.168.142.104 | SUCCESS | rc=0 >>
   Active: active (exited) since Mon 2018-02-26 17:48:34 CST; 1 day 18h ago

192.168.142.103 | SUCCESS | rc=0 >>
   Active: active (exited) since Mon 2018-02-26 17:49:06 CST; 1 day 18h ago

[[email protected]_master roles]#

ansible-doc -l  列出所有支持的模塊
            -s  列出模塊支持的動作
            -h
            -v 或-vvv 顯示詳細信息

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文標題:ansible 小技巧
本文鏈接:http://www.qdxgqk.live/?p=3691轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
?
?
萌宠夺宝游戏