Ansile (2) module cron

Source: Internet
Author: User

Ansible Cron module is a scheduled task, very simple

Backup: Back up the original scheduled task on the target host before operation

Cron_file: If this option is specified, replace the task schedule of the user under the CRON.D directory on the remote host with this file

Day: Specified date (1-31,*,*/1,...... )

Hour: Specify the hour (0-23,*,*/2, ...). )

minute: Specify minutes (0-59,*,*/3, ...). )

Month: Specify months (1-12,*,*/4, ...). )

Weekday: Specify Week (0-7,*, ...). )

Job: The task to be performed depends on the state=present

Name: Description of the task

Special_time: Specify when to execute, parameters: reboot,yearly,annually,monthly,weekly,daily,hourly

State: Verify that the task schedule is created or deleted

User: Who is executing as


1. Say a word to/tmp every minute

# ansible dbserver-m cron-a "Name= ' echo Ckl to tmp ' MINUTE=*/1 job= ' echo \" Ckl is good man\ ">>/tmp/kk.txt ' user= Root "172.16.110.49 | SUCCESS = {"Changed": True, "Envs": [], "Jobs": ["Echo Ckl to tmp"]}
# Crontab-l#ansible:echo Ckl to TMP*/1 * * * * echo "Ckl are good Man" >>/tmp/kk.txt
# cat Kk.txt Ckl is good mans


2. Write the scheduled task to a file in the target host

# ansible dbserver-m cron-a "Name= ' Mei Diao Yong ' cron_file=/root/ckl_cron.txt user=root job= ' minute=*/3/bin/bash/opt/ Script/df.sh ' "172.16.110.49 | SUCCESS = {"Changed": True, "Cron_file": "/root/ckl_cron.txt", "Envs": [], "Jobs": ["Mei Diao Yong "]}
# cat/root/ckl_cron.txt #Ansible: Mei Diao yong* * * * * Root minute=*/3/bin/bash/opt/script/df.sh


3. Back up the original task schedule before creating a new

# ansible dbserver -m cron -a  "name= ' test  back '  backup=yes user=root minute=*/2 job= '/bin/ls /root ' "            172.16.110.49 | SUCCESS => {      "Backup_file":  "/tmp/crontabu1wkmy",      "changed":  true,       "Envs": [],      "Jobs": [          "Echo ckl to tmp",           "Test back"     ]} 
# Crontab-l#ansible:echo Ckl to TMP*/1 * * * * echo ' Ckl is good man ' >>/tmp/kk.txt#ansible:test BACK*/2 * * * * /bin/ls/root

To view the backup:

# cat/tmp/crontabu1wkmy #Ansible: Echo Ckl to TMP*/1 * * * * echo "Ckl are good Man" >>/tmp/kk.txtyou has new mail In/var/spool/mail/root


This article is from the "take a deep Breath again" blog, make sure to keep this source http://ckl893.blog.51cto.com/8827818/1887029

Ansile (2) module cron

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.