I want to setup cronjobs on various servers at the same time for Data Mining. I was also already following the steps in Ansible and crontabs but so far nothing worked. Whatever i do, i get the Error Message:
ERROR: cron is not a legal parameter at this level in an Ansible Playbook
I have: Ansible 1.8.1
And for some unknown reasons, my Modules are located in:
/usr/lib/python2.6/site-packages/ansible/modules/
I would like to know which precise steps i have to follow to let Ansible install a new cronjob in the crontab file.
I'm asking this odd question because the documentation of cron is insufficient and the examples are not working. Maybe my installation is wrong too, which I want to test out with a working example of cron.
I've got (something very much like) this in a ./roles/cron/tasks/main.yml file:
- name: Creates weekly backup cronjob
cron: minute="20" hour="5" weekday="sun"
name="Backup mysql tables (weekly schedule)"
cron_file="mysqlbackup-WeeklyBackups"
user="root"
job="/usr/local/bin/mysqlbackup.WeeklyBackups.sh"
tags:
- mysql
- cronjobs
The shell script listed in the 'job' was created a little earlier in the main.yml file.
This task will create a file in /etc/cron.d/mysqlbackup-WeeklyBackups:
#Ansible: Backup mysql tables (weekly schedule)
20 5 * * sun root /usr/local/bin/mysqlbackup.WeeklyBackups.sh
---
- hosts: servers
tasks:
- name: "Cronjob Entry"
cron:
name: "### recording mixing/compressing/ftping scripts"
minute: 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57
hour: "*"
day: "*"
month: "*"
weekday: "*"
job: /usr/share/astguiclient/AST_CRON_audio_1_move_mix.pl
I am also getting below output.
#Ansible: ### recording mixing/compressing/ftping scripts
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /usr/share/astguiclient/AST_CRON_audio_1_move_mix.pl
If you're setting it up to run on the Crontab of the user:
- name: Install Batchjobs on crontab
cron:
name: "Manage Disk Space"
minute: "30"
hour: "02"
weekday: "0-6"
job: "home/export/manageDiskSpace.sh > home/export/manageDiskSpace.sh.log 2>&1"
#user: "admin"
disabled: "no"
become_user: "{{ admin_user }}"
tags:
- cronjobs
Reference [1]: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/cron_module.html#examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With