How to add MAILTO to a cron.d cron_file in Ansible?

Since Ansible 2.0 you have the cronvar command:

# modify /etc/cron.d/sweep_for_rebel_code
- cronvar:
    name: MAILTO
    value: vader@evilempire.com
    cron_file: sweep_for_rebel_code

See the official documentation at https://docs.ansible.com/ansible/latest/modules/cronvar_module.html


This works for me with ansible 2.1:

- cron:
    cron_file: ansible_test
    env: "{{ item.env }}"
    name: "{{ item.name }}"
    job: "{{ item.job }}"
    user: vagrant
  with_items:
    - env: true
      name: MAILTO
      job: test@test.com
    - env: false
      name: cmd
      job: /bin/true

Tags:

Cron

Ansible