# Cron Module failing

**URL:** <https://forum.ansible.com/t/cron-module-failing/13116>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [July 14, 2013, 1:47am UTC](https://forum.ansible.com/t/cron-module-failing/13116 "2013-07-14T01:47:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_CaJacob](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@Dan\_CaJacob](https://forum.ansible.com/u/Dan_CaJacob)\
**Post date:** [July 14, 2013, 1:47am UTC](https://forum.ansible.com/t/cron-module-failing/13116/1 "2013-07-14T01:47:30Z")

</div>

I have a role that uses the cron module to set three cron tasks. When I run ansible-playbook for this role, the first task will fail, but on the 2nd run, it will pass an the 2nd one will fail, on a subsequent run, the 1st and 2nd cron tasks will run, but the 3rd will fail. Running it again, all cron taks succeed and the play continues. Weird.

I am running ansible 1.2.2 on Ubuntu 13.04 x64

The relevant tasks (with some context) are:

> - name: copy aur binary to node  
> copy: src=$item  
> dest=/home/a/  
> owner=ais group=ais mode=755  
> with\_first\_found:
> - templates/config/$inventory\_hostname/config/aur
> - templates/ar/config/aur

> - name: setup minutely cron  
> sudo: yes  
> cron: name=“Minutely Tasks”  
> cron\_file=“ar”  
> user=“root”  
> job=“cd /home/sq/ar && run-parts --report /home/sq/ar/config/cron\_scripts/cron.minutely \> /home/sq/ar/logs/cron.minutely”
> - name: setup hourly cron  
> sudo: yes  
> cron: name=“Hourly Tasks”  
> cron\_file=“ar”  
> user=“sq”  
> minute=1  
> job=“cd /home/sq/ar && run-parts --report /home/sq/ar/config/cron\_scripts/cron.hourly \> /home/sq/ar/logs/cron.hourly”
> - name: setup daily cron  
> sudo: yes  
> cron: name=“Daily Tasks”  
> cron\_file=“ar”  
> minute=5  
> hour=1  
> user=“sq”  
> job=“cd /home/sq/ar && run-parts --report /home/sq/ar/config/cron\_scripts/cron.daily \> /home/sq/ar/logs/cron.daily”
> - name: import the python path in the crontab files  
> lineinfile: dest=/etc/cron.d/ar  
> insertbefore=BOF  
> regexp=^PYTHONPATH=  
> line=PYTHONPATH=$PYTHONPATH:/home/sq/ar/config:/home/sq/ar/config/shared

And the output near the failure is:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 14, 2013, 2:55am UTC](https://forum.ansible.com/t/cron-module-failing/13116/2 "2013-07-14T02:55:43Z")

</div>

There are some outstanding pull requests to improve the cron module.

Until we have a chance to test this, I’d possibly recommend using cron.d and templating those files.

–Michael

---

<div class="post-metadata">

**Author:** ![Max\_Kovgan](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@Max\_Kovgan](https://forum.ansible.com/u/Max_Kovgan)\
**Post date:** [September 2, 2013, 4:31pm UTC](https://forum.ansible.com/t/cron-module-failing/13116/3 "2013-09-02T16:31:02Z")

</div>

I’m using ansible 1.2.2, centos 6 (shipping with python 2.6)  
In tasks/main.yml I’m using this:

- name: Update crontab to run ntpdate once in 2 hours  
cron: name=“ntpdate update” minute=“{{ ntp.refresh\_minute }}” hour=“\*/2” user=root cron\_file=ntpdate\_periodic  
job=“/etc/init.d/ntpdate restart \> /dev/null”  
state=present

Still getting the following occasionally:  
fatal: [testbox] =\> failed to parse: Traceback (most recent call last):

File “/root/.ansible/tmp/ansible-1378136715.82-111243410056122/cron”, line 1258, in   
main()  
File “/root/.ansible/tmp/ansible-1378136715.82-111243410056122/cron”, line 346, in main  
(rc, out, err) = install\_jobs(module,user,tmpfile.name, cron\_file)  
TypeError: ‘NoneType’ object is not iterable  
Exception OSError: (2, ‘No such file or directory’, ‘/tmp/tmp8GnEv8’) in \<bound method \_TemporaryFileWrapper. **del** of \<closed file ‘’, mode ‘w+b’ at 0x7fd8108b7f60\>\> ignored

FATAL: all hosts have already failed – aborting

Looks like race to me.

What version is it supposed to be resolved at ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 2, 2013, 9:36pm UTC](https://forum.ansible.com/t/cron-module-failing/13116/4 "2013-09-02T21:36:56Z")

</div>

There are numerous cron fixes applied to Ansible 1.3, so can you please help test there?

If you are still seeing problems, please open a ticket in github.

Thanks!
