格式
ansible 主机或组 -m 模块名 -a '参数' ansible参数
ansible参数:
-C #测试什么内容会改变,不会真正去执行,主要用来测试一些可能发生的变化
-f 1-5 设置ansible并行的任务数,默认值为5
command
Ansible 的默认模块,可以运行远程权限范围所有的 shell 命令,
注意:客户端必须有python,且不支持管道符。
例:
shell > ansible Client -m command -a "free -m" # 查看 Client 分组主机内存使用情况
shell
其用法和command模块一样,不过shell模块执行命令的时候使用的是/bin/sh
注意:客户端必须有python,支持管道符。
例:
shell > ansible Client -m shell -a "/home/test.sh" # 执行远程脚本
shell > ansible Client -m shell -a "df -hT > /tmp/df.txt" # 管道符操作
raw
其用法与上两种差不多。
注意:客户端不需要有python,支持管道符。
例:
shell > ansible Client -m raw -a "yum -y install python3"
script
script 的功能是在远程主机执行主控端存储的 shell 脚本文件,相当于 scp + shell 组合。
注意:客户端不需要有python,支持管道符。
例:
shell > ansible Client -m script -a "/home/test.sh 12 34" # 远程执行本地脚本