- 需求
需要批量给一批次电脑添加定时任务 - 编写yml文件
# cat deploy_check_flanneld.yml
---
- name: 部署 flanneld 检查脚本 + 定时任务hosts: k8snodebecome: yestasks:- name: 分发检查脚本ansible.builtin.copy:# 源文件src: /data/scripts/check_flanneld.sh# 目标文件dest: /data/scripts/check_flanneld.sh mode: '0755'- name: 添加定时任务ansible.builtin.cron:name: "check flanneld and docker status"# 设置定时任务执行间隔minute: "*/30"user: "root"# 定时任务脚本job: "/bin/bash /data/scripts/check_flanneld.sh >> /var/log/check_flanneld.log 2>&1"
- 部署
# ansible-playbook deploy_check_flanneld.yml
执行过程
