阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ansible-cron模块

88次阅读
没有评论

共计 1422 个字符,预计需要花费 4 分钟才能阅读完成。

一、cron 模块

cron 模块用于管理周期性时间任务。

https://docs.ansible.com/ansible/latest/modules/cron_module.html#cron-module

参数 说明
name 计划任务的名称
user 执行计划任务的用户
job 计划任务命令
minute 执行计划任务的分 默认为 *
hour 执行计划任务的时 默认为 *
day 执行计划任务的日 默认为 *
month 执行计划任务的月 默认为 *
week 执行计划任务的周 默认为 *
state absent 删除计划任务

创建一个 cron 任务, 不指定 user 的话, 默认就是 root(因为我这里是用 root 操作的 )。
如果 minute,hour,day,month,week 不指定的话,默认都为 *

每天 14:23 执行 echo“haha”>/tmp/test

[root@manage01 ~]# ansible -m cron group1 -a 'name="cron test"user=root job="echo haha > /tmp/test"minute=23 hour=12' 192.168.98.203 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": ["cron test" ] } 192.168.98.202 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": ["cron test" ] } 192.168.98.201 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": ["cron test" ] }

删除 cron 任务

[root@manage01 ~]# ansible -m cron group1 -a 'name="cron test"state=absent' 192.168.98.203 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": []} 192.168.98.202 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": []} 192.168.98.201 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "envs": [], "jobs": []}

二、学习视频

视频:cron 模块

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-06-09发表,共计1422字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中