1.shell模块(远程安装vsftpd服务)
ansible all -m shell -a "yum install -y vsftpd"
2.script模块(不用将脚本发到其它机器上也能执行脚本/批量安装vsftpd服务)
ansible all -m script -a "/home/shell/vsftpd.sh"
3.copy模块
a.将本机的hosts文件移到所有机器的/etc目录下
ansible all(host文件里面所有ip) -m copy -a "src=/etc/hosts dest=/etc/"
b.将本机的hosts文件移到所有机器的/etc目录下,修改属主及权限,并对远程机器的源文件进行备份
ansible all -m copy -a "src=/home/shell dest=/home/ owner=zb group=zb mode=777 backup=yes"
3.1.fetch模块
将远程机器中的文件取到当前机器的/tmp目录下,并按照ip保存
ansible all -m fetch -a "src=/etc/hosts dest=/tmp"
4.file模块
a.在远程机器上创建文件,并设置属性,权限
ansible all -m file -a "dest=/etc/hosts owner=oldboy group=oldboy mode=666"
b.在远程机器上删除文件
ansible all -m file -a "dest=/etc/hosts state=absent"
c.创建链接文件信息:
ansible all -m file -a "src=/zb/zb.txt dest=/zb/zb_hard.txt state=hard" //软连接
ansible all -m file -a "src=/zb/zb.txt dest=/zb/zb_link.txt state=link" //硬链接
d.创建目录
ansible all -m file -a "dest=/home/zb/ state=directory"
e.递归改属主,权限
ansible all -m file -a "dest=/home/shell mode=777 recurse=yes"
5.yum模块
远程批量安装yum包
ansible all -m yum -a "name=iotop state=installed"
参数说明:
installed --- 安装软件
present
latest
absent --- 卸载软件
removed
6.service模块
远程启动nfs服务,并开机自启
ansible all -m service -a "name=nfs state=started enabled=yes"
参数说明:
name: --- 指定管理的服务名称
state: --- 指定服务状态
started 启动
restarted 重启
stopped 停止
enabled --- 指定服务是否开机自启动
7.cron模块
a.给远程机器添加定时对时任务,并增加注释说明
ansible all -m cron -a "name='time sync' minute=0 hour=2 job='/usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1'"
b.删除ansible添加的定时任务信息
ansible all -m cron -a "name='time sync01' state=absent"
c.注释ansible添加的定时任务信息
ansible all -m cron -a "name='time sync' minute=0 hour=2 job='/usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1 disabled=yes"
8.mount模块
把99机器上data目录通过nfs方式批量挂载到每台机器上/mnt
ansible all -m mount -a "src=/192.168.6.99:/data path=/mnt fstype=nfs state=mount"
参数说明:
src: 需要挂载的存储设备或文件信息
path: 指定目标挂载点目录
fstype: 指定挂载时的文件系统类型
state
present: 不会实现立即挂载,修改fstab文件,实现开机自动挂载
mounted: 会实现立即挂载, 并且会修改fstab文件,实现开机自动挂载 *****
absent: 会实现立即卸载, 并且会删除fstab文件信息,禁止开机自动挂载
unmounted: 会实现立即卸载, 但是不会会删除fstab文件信息 *****