11. cron模块
9. cron模块¶
1. 作用¶
# 添加定时任务
2. 案例¶
#1. 安装ntpdate服务
ansible ali -m yum -a "yum install ntpdate -y"
#2. 每5分钟进行事件同步(注意:命令必须写绝对路径!)
ansible ali -m cron -a "name=ntp_cron job='/usr/sbin/ntpdate -u ntp.aliyun.com > /dev/null 2>&1' minute=*/5"
#3. 远程检查定时任务确认
ansible ali -m shell -a "crontab -l"
3. 案例2¶
# 要求:每个月的3号和13号的8:00 重启nginx
ansible ali -m cron -a "name=restart_nginx job='usr/bin/systemctl restart nginx' minute=0 hour=8 day=3,13"
# 删除定时任务
ansible ali -m cron -a "name='restart_nginx' state=absent"
最后更新:
2022-02-18 11:26:47