1. cron模塊
功能:管理被控端計划任務;
主要參數如下:
| 參數 | 說明 |
|---|---|
| name | 定時任務基本描述 |
| job | 定時任務要執行的命令 |
| minute | 分 |
| hour | 小時 |
| day | 日 |
| month | 月 |
| weekday | 周,0-6 |
| disabled | yes:禁用計划任務,no:啟用計划任務 |
| absent:刪除計划任務 |
-
示例一:創建計划任務,每10分鍾執行一次同步時間,將此計划任務命名為
synctime;[root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="synctime" job="ntpdate 192.168.20.1 &> /dev/null" minute=*/10' [root@nginx03 ~]# crontab -l #Ansible: synctime */10 * * * * ntpdate 192.168.20.1 &> /dev/null -
示例二:添加定時任務, 每天的凌晨2點和凌晨5點執行一次
ls:[root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="ls" job="ls &> /dev/null" minute=0 hour=2,5' [root@nginx03 ~]# crontab -l #Ansible: synctime */10 * * * * ntpdate 192.168.20.1 &> /dev/null #Ansible: ls 0 2,5 * * * ls &> /dev/null -
示例三:禁用上面示例的計划任務:
[root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="ls" job="ls &> /dev/null" minute=0 hour=2,5 disabled=yes' [root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="synctime" job="ntpdate 192.168.20.1 &> /dev/null" minute=*/10 disabled=yes' #被控主機被注釋掉了 [root@nginx03 ~]# crontab -l #Ansible: synctime #*/10 * * * * ntpdate 192.168.20.1 &> /dev/null #Ansible: ls #0 2,5 * * * ls &> /dev/null -
示例四:刪除上述的計划任務:
[root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="synctime" state=absent' [root@xuzhichao ~]# ansible NginxWebs -m cron -a 'name="ls" state=absent'
