Cron Module failing

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:

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

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 ?

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!