Skip to content

cron

Manages a single per-user crontab entry, identified by the declaration name and tagged with a marker comment so only that entry is owned. Idempotent: re-applying an unchanged declaration reports no change.

Category: Scheduled tasks

States

StateMeaning
presentThe user’s crontab has an entry tagged with the declaration name, carrying the declared schedule and command.
absentThe user’s crontab has no entry tagged with the declaration name; an existing tagged entry is removed.

Parameters

ParameterTypeRequiredDescription
commandstringyesThe command line to run (single line). Required for state present; rejected for absent.
schedulestringyesA five-field cron spec (*/5 * * * *) or an @-shortcut (@daily, @reboot, …). Required for state present; rejected for absent.
userstringOwner of the crontab to manage. Default: root.

Examples

Run a nightly backup

cron:
  nightly-backup:
    state: present
    command: /usr/bin/backup
    schedule: "0 2 * * *"
    user: root

Per-user job with an @-shortcut

cron:
  app-cache-warm:
    state: present
    command: /opt/myapp/bin/warm-cache
    schedule: "@hourly"
    user: myapp

Remove a job

Only the entry tagged with this name is removed; other crontab lines are left alone.

cron:
  old-cleanup:
    state: absent
    user: root

Notes

  • Linux only; the module shells out to crontab(1) and fails when that binary is absent.
  • Manages exactly the entry tagged # keystone-cron: <name>; other crontab lines are never touched.
  • command and schedule are required for present and rejected for absent.
  • schedule field contents are not deeply validated — only field count and known @-shortcuts.
  • Out of scope (planned, #105): per-field schedule params, /etc/cron.d drop-ins, environment lines.