CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Scheduled Tasks with cron

The cron module is idempotent in a way that is worth understanding, because the mechanism is visible in the crontab itself: it writes a comment containing the job's name and finds the job again by that comment. Change the schedule and it updates in place. Change the name and it has no idea the old one was yours.

Automating Administration Guide 34 of 45 Beginner

This lab is Ubuntu 26.04 and EX294 is a RHEL exam. cron is the same on both, though the package differs - cron on Debian and Ubuntu, cronie on RHEL. cron_file writes into /etc/cron.d/ and requires user: to be set, because a system crontab has a user field that a personal one does not.

One managed node. Jobs are created in root's crontab and in /etc/cron.d, then removed.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

This guide includes

Use this when a cron job must not be created twice. This matters because the cron module identifies a job by its comment - so renaming one gives you two identical jobs rather than one renamed job.

Before you start

  1. The configuration this guide assumes

  2. A cron job, and the comment that identifies it

  3. Rename it and get two

  4. System-wide jobs and environment variables

  5. Disabling rather than deleting

Official sources