自动化-ansible实现远程任务计划
一:实现远程任务计划
示例:ansible 192.168.1.252 -m cron -a "name='ghs cron' job='/bin/bash /tmp/1.sh' day=1"
name:后面定义的是给这个任务计划定义个名字
job:定义是操作的行为
weekday:每周
day:天
minute:分钟
hour:小时
month:月份
host1:192.168.1.251
1:使用ansible远程实现任务计划,每个周6执行/tmp/1.sh脚本
[root@ghs ~]# ansible 192.168.1.252 -m cron -a "name='ghs cron' job='/bin/bash /tmp/1.sh' weekday=6"
192.168.1.252 | SUCCESS => {
"changed": true,
"envs": [],
"jobs": [
"ghs cron"
]
}
2:查看远程机上的任务计划列表
[root@ghs2 ~]# crontab -l
#Ansible: ghs cron
* * * * 6 /bin/bash /tmp/1.sh
3:删除远程任务计划
[root@ghs ~]# ansible 192.168.1.252 -m cron -a "name='ghs cron' state=absent"
192.168.1.252 | SUCCESS => {
"changed": true,
"envs": [],
"jobs": []
}
host2:192.168.1.252
4:查看是否还有任务计划列表
[root@ghs2 ~]# crontab -l
You have new mail in /var/spool/mail/root
记录每一天有趣的事情!!

浙公网安备 33010602011771号