ansible 小技巧
ansible 常用模块之command/shell/raw
是否支持管道
module 是否支持管道
command 不支持管道
shell 支持管道——–
raw 支持管道 ——–
使用方法
[root@ ~]# ansible localhost -m command -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff
[root@ ~]# ansible localhost -m shell -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff
[root@ ~]# ansible localhost -m raw -a "echo hello"
localhost | SUCCESS | rc=0 >>
hello jeff
直接执行某个文件
[root@ ~]# ansible host32 -m command -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff
[root@ ~]# ansible host32 -m raw -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff
[root@ ~]# ansible host32 -m shell -a "/tmp/ttt.sh"
host32 | SUCCESS | rc=0 >>
hello jeff
[root@ansible_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
[root@ansible_master roles]#
ansible-doc -l 列出所有支持的模块
-s 列出模块支持的动作
-h
-v 或-vvv 显示详细信息
暂时还木有人评论,坐等沙发!