Ansible 远程执行脚本

1. 先在服务端创建一个 shell 脚本

[root@localhost ~]$ cat /tmp/test.sh 
#!/bin/bash
echo "hello world"

2. 把脚本分发到客户端

[root@localhost ~]$ ansible 192.168.119.134 -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"

3. 远程执行脚本,使用 shell 模块

[root@localhost ~]$ ansible 192.168.119.134 -m shell -a "/tmp/test.sh"
192.168.119.134 | CHANGED | rc=0 >>
hello world

 

 

 

 

 

    

posted @ 2019-01-03 11:57  孔雀东南飞  阅读(7150)  评论(0编辑  收藏  举报