Cron job issues

All,

I’m currently trying to compose a playbook to remove log files that are older than 90 days and then gzip the remaining files that are older than 7 days.

I’m attempting to use the cron module of Ansible to do this but havign a bit of trouble.

Here’s what I’ve done so far:

Created a job in my main.yml file

`

  • name: Cron job to purge log files older than 90 days and gzip files on a daily rotation
    cron: minute=“59” hour=“23” weekday=“*”
    name=“freeradius log file rotation”
    cron_file=“freeradius”

user=“root”
job=“/etc/cron.d/freeradius”
tags:

  • cronradius

`

My cron_file (freeradius) looks like this:

find /var/log/freeradius/radacct/ -mtime +90 -print0 | xargs -0 rm && find /var/log/freeradius/radacct/ -type f -mtime +7 -print0 | xargs -0 gzip

When I run the playbook against a server it copies the freeradius file across to /etc/cron.d/freeradius but when I “type” the contents of that file it displays:

`
59 23 * * * root /etc/cron.d/freeradius

`

and as a result I think this is incorrect, it appears to not be referencing the find command…

Any ideas what I am doing wrong?

Regards
Colin

job is the command to execute, here you are making it the same as the
cron file itself. You either want to make this a copy (since you
already wrote out the cron job) or

job='find /var/log/freeradius/radacct/ -mtime +90 -print0 | xargs -0
rm && find /var/log/freeradius/radacct/ -type f -mtime +7 -print0 |
xargs -0 gzip'

Brian,

That’s great - thank you! I’ve made the change and that’s just what I’m after.

Regards