# Cron job issues

**URL:** <https://forum.ansible.com/t/cron-job-issues/18470>\
**Category:** Ansible Project\
**Created:** [June 11, 2015, 2:23pm UTC](https://forum.ansible.com/t/cron-job-issues/18470 "2015-06-11T14:23:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@Colin\_Phillips](https://forum.ansible.com/u/Colin_Phillips)\
**Post date:** [June 11, 2015, 2:23pm UTC](https://forum.ansible.com/t/cron-job-issues/18470/1 "2015-06-11T14:23:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 11, 2015, 2:29pm UTC](https://forum.ansible.com/t/cron-job-issues/18470/2 "2015-06-11T14:29:38Z")

</div>

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'

---

<div class="post-metadata">

**Author:** ![Colin\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@Colin\_Phillips](https://forum.ansible.com/u/Colin_Phillips)\
**Post date:** [June 11, 2015, 2:38pm UTC](https://forum.ansible.com/t/cron-job-issues/18470/3 "2015-06-11T14:38:50Z")

</div>

Brian,

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

Regards
