jasonaburton
jasonaburton

Reputation: 3103

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    

Upvotes: 12

Views: 3685

Answers (1)

helloV
helloV

Reputation: 52423

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

Upvotes: 23

Related Questions