Ansible 来修改 crontab 文件并添加计划任务。用于将你提供的 cron 行添加到特定用户的 crontab 中:
---
- name: Add cron job to user's crontab
hosts: your_target_host
tasks:
- name: Add cron job
cron:
name: "ntpdate_job"
minute: "0"
hour: "10"
job: "ntpdate 192.168.69.54 >> /var/log/ntpdate.log"
user: your_username
确保将 your_target_host 替换为目标主机的名称或 IP 地址,将 your_username 替换为要添加 cron 任务的用户的用户名。
运行此 Playbook 将使用 Ansible 在指定的用户的 crontab 中添加新的 cron 任务。文章来源:https://www.toymoban.com/news/detail-669840.html
执行命令ansible-playbook add_cron_job.yaml
文章来源地址https://www.toymoban.com/news/detail-669840.html
到了这里,关于ansible批量创建crontab文件并添加到定时任务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!