/home/travis/.ansible/roles/robertdebock.cron/tasks/main.yml
---
# tasks file for cron
- name: include assert.yml
  include_tasks: assert.yml
  run_once: yes

- name: install cron
  package:
    name: "{{ cron_packages }}"
    state: present

- name: configure shell
  lineinfile:
    path: "{{ cron_configuration }}"
    line: "SHELL={{ cron_shell }}"
    regexp: "^SHELL"
    create: yes
    mode: "0644"
  notify:
    - restart cron

- name: configure path
  lineinfile:
    path: "{{ cron_configuration }}"
    line: "PATH={{ cron_path }}"
    regexp: "^PATH"
    create: yes
    mode: "0644"
  notify:
    - restart cron

- name: configure mailto
  lineinfile:
    path: "{{ cron_configuration }}"
    line: "MAILTO={{ cron_mailto }}"
    regexp: "^MAILTO"
    create: yes
    mode: "0644"
  notify:
    - restart cron

- name: start and enable cron
  service:
    name: "{{ cron_service }}"
    state: started
    enabled: yes
  when:
    - cron_service | length

- name: schedule requested cron jobs
  cron:
    name: "{{ item.name }}"
    minute: "{{ item.minute | default(omit) }}"
    hour: "{{ item.hour | default(omit) }}"
    day: "{{ item.day | default(omit) }}"
    month: "{{ item.month | default(omit) }}"
    weekday: "{{ item.weekday | default(omit) }}"
    job: "{{ item.job }}"
    state: "{{ item.state | default('present') }}"
    user: "{{ item.user | default(omit) }}"
  loop: "{{ cron_jobs }}"
  loop_control:
    label: "{{ item.name }}"
  notify:
    - restart cron
  when:
    - cron_jobs is defined