您的位置:首页 > 其它

3.4-ansible远程执行脚本

2016-04-06 20:35 176 查看
Ansible远程执行脚本

* 首先创建一个shell脚本
vim /tmp/test.sh //加入内容
#!/bin/bash
echo `date` > /tmp/ansible_test.txt
* 然后把该脚本分发到各个机器上
ansible testhost -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
* 最后是批量执行该shell脚本
ansible testhost -m shell -a "/tmp/test.sh"
* shell模块,还支持远程执行命令并且带管道
ansible testhost -m shell -a "cat /etc/passwd|wc -l "

说明:如果test.sh没有执行权限,可以用ansible testhost -m shell -a "/bin/sh /tmp/test.sh"来实现脚本的执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: