Ansible Module - SCHEDULED TASKS
add a cron job Clear Lastlog on node00 to empty the /var/log/lastlog logs file. The job must run at 12am everyday.
- hosts: node00
tasks:
- cron:
job: echo "" > /var/log/lastlog
month: "*"
day: "*"
hour: "0"
minute: "0"
execute this script after every 2 hour (i.e 12am, 2am, 4am etc), the command to execute the script is sh /root/free.sh and schedule should be 0 /2 * *
- hosts: node00
tasks:
- cron:
job: sh /root/free.sh
month: "*"
day: "*"
hour: "*/2"
minute: "*"
remove cron job from node00
- name: remove cron job from node00
hosts: node00
tasks:
- name: Remove cron job
cron:
name: "Check Memory" ; cron job name
state: absent
Add a cron named cleanup on node00 that will execute after every reboot and will clean /tmp location.
- hosts: node00
tasks:
- cron:
name: cleanup
job: rm -rf /tmp/*
special_time: reboot
special_time:
- annually
- daily
- hourly
- monthly
- reboot
- weekly
- yearly
On node00 we want to keep the installed packages up to date, so we would like to run yum updates regularly. Create a playbook ~/playbooks/yum_update.yml and create a cron job as described below:
a. Do not add cron directly using crontab instead create a cron file /etc/cron.d/ansible_yum.
b. The cron must run on every Sunday at 8:05 am.
c. The name of the cron must be yum update.
d. Cron should be added for user root
- name: Create cron for yum
hosts: node00
gather_facts: no
tasks:
- name: Creates a cron
cron:
name: yum update
weekday: 0
minute: 5
hour: 8
user: root
job: "yum -y update"
cron_file: ansible_yum
-
user: The specific user whose crontab should be modified.
-
cron_file: 상대 경로인 경우 /etc/cron.d에 대해 해석됩니다.
Author And Source
이 문제에 관하여(Ansible Module - SCHEDULED TASKS), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@codingdaddy/Ansible-Module-SCHEDULED-TASKS저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)