Search code examples
cronansible

Ansible with_items keeps overwriting last line of loop


This is my playbook. Pretty simple. The problem is with the "with_items". It iterates over all the items, but, it only writes the last item to the crontab file. I think it is overwriting it. Why is this happening?

- name: Create cron jobs to send emails                                       
  cron:                                                                                        
    name="Send emails"                                                          
    state=present                                                                              
    special_time=daily                                                                         
    job="/home/testuser/deployments/{{ item }}/artisan --env={{
item }} send:healthemail"                                                                 
  with_items:
      - london 
      - toronto
      - vancouver    

Solution

  • The cron module expects the job name to be unique. Change it to:

    name="Send emails {{ item }}"
    

    See: cron – Manage cron.d and crontab entries