Pages

Friday, 27 December 2019

EX294: Scheduled tasks modules

Just as we have "at" and "cron" commands, Ansible provides two modules accordingly.

  • at
  • cron
Both "at" and "cron" modules are NOTguaranteed to be backward compatible. 

1. at

Currently, the "at" module is less flexible than "at" command regarding the time expressions.

e.g.


- name: Schedule a command to execute in 20 minutes as current user
  at:
    command: ls -d / >/dev/null
    count: 20
    units: minutes

2. cron

The "cron" module identify a cron job by the job's name which exists in a comment line just above the job line.

$ ansible localhost -m cron -a 'name="test job" minute=0 hour="1,13" job="ls /"'

$ crontab -l
#Ansible: test job
0 1,13 * * * ls /

Note:
The official document about "cron" module has an error.

user
string
The specific user whose crontab should be modified.
When unset, this parameter defaults to using root.

In fact, if "user" is unset, the default is the current user, the one used for ansible connection.

No comments:

Post a Comment