1、command
command 作为 Ansible 的默认模块,可以运行远程权限范围所有的 shell 命令,不支持管道符。
ansible Client -m command -a "free -m"
2、script
远程执行本地脚本
script 的功能是在远程主机执行主控端存储的 shell 脚本文件,相当于 scp + shell 组合。
ansible all -m script -a "/home/test.sh 12 34
3、shell
shell模块基本和command相同,但是shell支持管道符
ansible Client -m shell -a "/home/test.sh"
4、copy模块
向 Client 组中主机拷贝 test.sh 到 /tmp 下,属主、组为 root ,权限为 0755,src为本地目录,dest目标路径
ansible all -m copy -a "src=/home/test.sh dest=/tmp/ owner=root group=root mode=0755"
5、stat模块-获取远程文件状态信息
ansible all -m st at -a "path=/etc/syctl.conf"
6、get_url 实现在远程主机下载指定URL到本地,支持sha256sum文件校验
ansible all -m get_url -a "url=http://www.baidu.com dest=/tmp/index.html mode=0440 force=yes"
7、yum 软件包管理
ansible all -m yum -a "name=curl state=latest"
8、corn 远程控制住进得crontab配置
ansible all -m cron -a "name='check dirs' hour='5,2' job='ls -alh > /dev/null'"
9、mount 远程主机分区挂载
ansible all -m mount -a "name=/mnt/data src=/dev/sd0 fstype=ext4 opts=ro state=present"
10、service 远程主机系统服务管理
ansible all -m service -a "name=nginx state=stoped"
ansible all -m service -a "name=nginx state=restarted"
ansible all -m service -a "name=nginx state=reloaded"
11、user 远程主机用户管理
ansible all -m user -a "name=wang comment='user wang'"
ansible all -m user -a "name=wang state=absent remove=yes" #添加删除用户