帮助命令
# ansible-doc -l # 列出所有可用模块;
# ansible-doc -s MODULE_NAME # 获取具体模块的使用方法;
模块案例
command
# 命令模块,默认模块(不写时默认有),用于远程执行命令;
# ansible all -a 'date'
shell
# 执行远程服务器上的脚本
# ansible all -m shell -a "/home/a.sh "
scripts
# 在远程服务器上执行主控服务器脚本
# ansible all -m scripts -a "/home/a.sh arg1 arg2"
cron
# ansible all -m cron -a "name='test' hour='2-5' minute='*/5' day='1' month='3,4' weekday='1' job='ls -l' user=tom"
# ansible all -a 'crontab -l -u tom'
copy
# ansible all -m copy -a 'src=/etc/fstab dest=/tmp/fstab.ansible owner=root mode=640'
# 将目标文件内容替换为content中内容
# ansible all -m copy -a 'content="Hello Ansible Hi " dest=/tmp/kazihuo.ansible'
synchronize
# 将master上文件批量下发,src为master上的文件路径,dest为目标服务器上的文件路径
# ansible all -m synchronize -a "src=/tmp/test/ dest=/tmp/test/"
file
# ansible all -m file -a 'owner=mysql group=mysql mode=777 path=/tmp/kazihuo.ansible'
group
# ansible webserver -m group -a 'name=mysql gid=306 system=yes'
user
# ansible all -m user -a 'name=mysql uid=306 system=yes group=mysql'
# ansible all -m user -a "name=mysql state=absent remove=yes" #删除用户
link
# ansible all -m file -a 'path=/tmp/fstab.link src=/tmp/fstab.ansible state=link'
ping
# ansible all -m ping
service
# ansible all -a 'systemctl status httpd.service'
# ansible all -m service -a 'enabled=true name=httpd state=started'
yum
# ansible all -m yum -a 'name=zsh state=present'
# ansible dbserver -m yum -a 'name=httpd state=absent'
setup
# 收集远程主机的facts(每个被管理节点在接收并运行管理命令之前,会将自己主机相关信息,如操作系统版本、IP地址等报告给远程的ansible主机)
# ansible all -m setup