[root@m01 ~]# ansible zeq -m file -a "path=/tmp/zeq state=diretory"
[root@m01 ~]# ansible zeq -m file -a "path=/tmp/tt state=touch mode=555 owner=root group=root"
[root@m01 ~]# ansible zeq -m file -a "src=/tmp/tt path=/tmp/tt_link state=link"
3.8 crond模块
正常使用crond服务
[root@m01 ~]# crontab -l
* * * * * /bin/sh /server/scripts/yum.sh
使用ansible添加一条定时任务
[root@m01 ~]# ansible zeq -m cron -a "minute=* hour=* day=* month=* weekday=* job='/bin/sh /server/scripts/test.sh'"
[root@m01 ~]# ansible zeq -m cron -a "job='/bin/sh /server/scripts/test.sh'"
设置定时任务注释信息,防止重复,name设定
[root@m01 ~]# ansible zeq -m cron -a "name='cron01' job='/bin/sh /server/scripts/test.sh'"
删除相应定时任务
[root@m01 ~]# ansible zeq -m cron -a "name='ansible cron02' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' state=absent"
注释相应定时任务,使定时任务失效
[root@m01 scripts]# ansible zeq -m cron -a "name='ansible cron01' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' disabled=no"
3.9 mount模块
参数
说明
mounted
挂载设备,并将配置写入/etc/fstab
unmounted
卸载设备,不会清除/etc/fstab写入的配置
absent
卸载设备,会清理/etc/fstab写入的配置
fstype
指定挂载文件类型
opts
设定挂载的参数选项信息
path
指定挂载点
[root@m01 ~]# ansible zeq -m mount -a "path=/backup src=https://www.linuxidc.com/10.0.0.31:/data fstype=nfs opts=defautls,noatime state=mounted"
3.10 ansible查看帮助方法
ansible-doc -l --- 查看所有模块说明信息
ansible-doc copy --- 表示指定查看某个模块参数用法信息
第4章 ansible实战应用
4.1 推送你的公钥(免密登录)
[root@m01 ~]# sshpass -p1 ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.41
4.2 配置Ansible的主机清单
[root@m01 ~]# cat /etc/ansible/hosts
[web]
172.16.1.7
172.16.1.8
[nfs]
172.16.1.31
[backup]
172.16.1.41
4.3 检查主机是否都ok
[root@m01 ~]# ansible all -m ping
epel、firewalld、selinux、ww
4.4 基础环境: