Cron job issues

46 views
Skip to first unread message

Colin Phillips

unread,
Jun 11, 2015, 10:25:38 AM6/11/15
to ansible...@googlegroups.com, Colin M. Phillips
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

Brian Coca

unread,
Jun 11, 2015, 10:29:42 AM6/11/15
to ansible...@googlegroups.com, Colin M. Phillips
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'
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5bc3ae2e-bd6c-4d3a-ad36-c4bcdcd502d1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Colin Phillips

unread,
Jun 11, 2015, 10:38:50 AM6/11/15
to ansible...@googlegroups.com, co...@colskinet.co.uk
Brian,

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

Regards
Reply all
Reply to author
Forward
0 new messages