Getting started
Randomized system jobs
The role modifies the /etc/crontab
configuration file to randomize
execution times of hourly
, daily
, weekly
and monthly
cron jobs. This is done to avoid huge spikes of job execution every
day around 06:25 which is the default execution time defined in the Debian and
Ubuntu cron
package. The randomization is defined with the following rules:
Each type of cron job will have randomized minute at which the jobs will be executed.
On each host, the role will choose a specific hour for each of the
daily
,weekly
andmonthly
jobs. The list of allowed hours is defined in thecron__crontab_hours
variable.The
weekly
cron jobs will be executed on either Saturday or Sunday, chosen randomly. you can specify what days to choose from using thecron__crontab_weekday_days
variable.The
monthly
cron jobs will be executed on a randomized day of the first week of a month. This is controlled by thecron__crontab_day_ranges
variable.
The randomization is based on the cron__crontab_seed
variable (by
default uses the value of the inventory_hostname
Ansible fact), as well as
some additional pseudo-random strings hashed in the
cron__crontab_offset_seeds
list. The hashes are stored in the
debops.cron Ansible local fact script for idempotency; the script can be
removed to regenerate a new set of hashes if the resulting execution times are
not the desired ones.
Example inventory
debops.cron
is included by default in the common.yml
DebOps playbook;
you don't need to do anything to have it executed.
If you don’t want to let debops.cron
manage the cron jobs, you
can do this with the following setting in your inventory:
cron__enabled: False
Example playbook
If you are using this role without DebOps, here's an example Ansible playbook
that uses the debops.cron
role:
---
- name: Manage cron jobs
collections: [ 'debops.debops', 'debops.roles01',
'debops.roles02', 'debops.roles03' ]
hosts: [ 'debops_all_hosts', 'debops_service_cron' ]
become: True
environment: '{{ inventory__environment | d({})
| combine(inventory__group_environment | d({}))
| combine(inventory__host_environment | d({})) }}'
roles:
- role: cron
tags: [ 'role::cron', 'skip::cron' ]