crontool
Paste a schedule, read it in English, see the next runs.

Running an Ansible Playbook with Cron

Call ansible-playbook by its absolute path with explicit -i inventory and playbook paths, since cron has no working directory context. Redirect output to a log so you can review each scheduled run.

The crontab line

0 5 * * * /usr/bin/ansible-playbook -i /opt/infra/hosts /opt/infra/site.yml >> /var/log/ansible-cron.log 2>&1

Use absolute paths for the inventory (-i) and the playbook — cron won't be in your project directory.

Point at ansible.cfg

Set the config explicitly so cron picks up your settings: ANSIBLE_CONFIG=/opt/infra/ansible.cfg before the command, or at the top of the crontab.

SSH keys and become

Ansible needs the SSH key non-interactively. Use a key without a passphrase for the cron user, or load an agent. For privilege escalation add --become with passwordless sudo on the targets.

FAQ

How do I run an Ansible playbook from cron?

0 5 * * * /usr/bin/ansible-playbook -i /opt/infra/hosts /opt/infra/site.yml. Use absolute paths for the binary, inventory, and playbook.

How does cron find ansible.cfg?

Set ANSIBLE_CONFIG=/opt/infra/ansible.cfg before the command, since cron won't run from your project directory where ansible.cfg normally sits.

How do I handle SSH keys for Ansible in cron?

Use a passphrase-less key for the cron user or load an ssh-agent, because cron can't answer an interactive passphrase prompt.