DevOps ansible 一行命令例子

laofo · 2017年05月24日 · 最后由 laofo521@gmail.com 回复于 2017年06月28日 · 0 次阅读
ansible test-server -i ./hosts -m raw -a "hpssacli ctrl slot=0 show config detail | grep 'Firmware Version:'"

其中 hosts 文件中有一个 test-server 段,写了我要操作的机器

[test-server]
192.168.1.101

查看这些机器是否可以访问百度

ansible test-server -i ./hosts -m raw -a "wget baidu.com"

查看这些机器上都有哪些 docker 镜像

ansible test-server -i ./hosts -m raw -a "docker images"
ansible sever-to-pull-images -i ./hosts -m raw -a "killall yum"
ansible sever-to-pull-images -i ./hosts -m raw -a "ps aux | grep yum | cut -c  11-14 | xargs kill -9" 
ansible sever-to-pull-images -i ./hosts -m raw -a "ps aux | grep yum |awk '{print $2}'|xargs kill -9"
ansible sever-to-pull-images -i ./hosts -m raw -a "ps aux | grep yum"
ansible sever-to-pull-images -i ./hosts -m raw -a " yum install -y kpatch"
ansible sever-to-pull-images -i ./hosts -m raw -a " yum -ql   kpatch"
ansible sever-to-pull-images -i ./hosts -m raw -a "lsmod |  grep -E 'kpatch|hotfix_rhash'"

ansible sever-to-pull-images -i ./hosts -m raw -a "ps aux | grep /home | grep -v grep | awk '{print $2}'"

ansible all  -m raw -i 192.168.1.1,  -a "lsmod | grep kpatch"

注意一台机器后面也要有个逗号,且选择的机器要用 all

#在远程主机上执行命令
#ansible all  -i $IP,  -m raw -a "lsmod | grep kpatch"
#在远程主机上执行本地主机的脚本(copy+exec+del)
#ansible all  -i $IP,  -m script -a '/home/start-service.sh'
需要 登录 后方可回复。