侧边栏壁纸
  • 累计撰写 221 篇文章
  • 累计创建 205 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

ansible 远程执行脚本

zhanjie.me
2018-08-04 / 0 评论 / 0 点赞 / 0 阅读 / 0 字

ansible 远程执行脚本

  首先创建一个shell脚本

[root@server ~]# vim /tmp/test.sh

#!/bin/bash

echo `date` > /tmp/ansible_test.txt

  然后把该脚本分发到各个机器上

[root@server ~]# ansible testhosts -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"

  批量执行该脚本

[root@server ~]# ansible testhosts -m shell -a "/tmp/test.sh"

client.test.com | SUCCESS | rc=0 >>



127.0.0.1 | SUCCESS | rc=0 >>

  查看一下

[root@server ~]# ansible testhosts -m shell -a "cat /tmp/ansible_test.txt"

127.0.0.1 | SUCCESS | rc=0 >>

2016年 07月 10日 星期日 23:44:13 CST



client.test.com | SUCCESS | rc=0 >>

2016年 07月 10日 星期日 23:44:20 CST

  shell模块,还支持远程执行命令并且带管道符

[root@server ~]# ansible testhosts -m shell -a "cat /etc/passwd|wc -l"

127.0.0.1 | SUCCESS | rc=0 >>

26



client.test.com | SUCCESS | rc=0 >>

26
0

评论区