1.先在服务端创建一个 shell 脚本
[root@localhost ~]$ cat /tmp/test.sh
#!/bin/bash
echo "hello world"
2.把脚本分发到客户端
[root@localhost ~]$ ansible 192.168.56.100 -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
[root@localhost ~]$ ansible 192.168.56.100 -m shell -a "/tmp/test.sh"
192.168.56.100 | CHANGED | rc=0 >>
hello world