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

    

原文地址:https://www.cnblogs.com/pzk7788/p/10213459.html