All,
Can a playbook be run by ‘job’, i.e. instead of a script.
I created a playbook that creates an entry in crontab, which it does successfully, but it does not execute the playbook I specified in job:
Thanks!
John
All,
Can a playbook be run by ‘job’, i.e. instead of a script.
I created a playbook that creates an entry in crontab, which it does successfully, but it does not execute the playbook I specified in job:
Thanks!
John
More information would be helpful here.
Can you share your usage of ansible.builtin.cron?
Can you share the output of crontab -l for the user you’re creating the cron job for/as, or the contents of /etc/crontab and/or /etc/cron.* ?
What’s in your cronlog or systemd journal?
Obvious question but you do have a vixie cron variant installed and the appropriate services started?
Things run from cron usually have a very limited set of time environments variables available to them.
I assume you have no output at all now, so you don’t know where to start looking.
Start by ensuring that you receive any output from cron (pipe to email, write to log, whatever is appropriate in your use case)
That will reveal the reason why it’s not working.
job: “/home/jwelby/ansible/sub-playbooks/ansible-playbook -i dev-hosts /home/jwelby/ansible/sub-playbooks/patching.yml”
30 15 * * 3 /home/jwelby/ansible/sub-playbooks/patching.yaml
These don’t match. cron isn’t running ansible-playbook. It is trying to run the YAML file itself.
Walter
Also the file name extensions are different (yml vs yaml). Are we looking at some copy paste errors?
There’s a discrepancy between your job as defined in your playbook and your output as listed from crontab -l. I suspect that’s just transcription but worth double-checking? (Walter and Dick have also spotted that.)
I’d also check that the ec2-user which is who you’re creating the crontab as has appropriate permissions and ownership of /home/jwelby/ and can descend into that tree and “do stuff”.
And finally, check your logs/journal. As Dick mentioned, the cron execution environment is restrictive, so it’s likely whatever’s happening will be logged under _COMM = crontab or UNIT crontab.service.
I’d get it working with a simple debug job firing every 5 minutes with a playbook which just runs a debug or touches a file, check for its execution successfully in the journal logs then increase the complexity in stages.
Yes, there are copy/paste errors as I am transcribing and scrubbing info from a high-side environment.
It works as expected for me on a test Fedora machine.
As a test user, create a debug playbook and test it runs.
[test-user@fedora ~]$ id
uid=1001(test-user) gid=1001(test-user) groups=1001(test-user) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[test-user@fedora ~]$ cat debug.yaml
Thanks, I will try that.