---

- name: (cron.yml) Set env entries in user crontabs
  cron:
    name: '{{ item.name }}'
    env: 'yes'
    user: '{{ item.user | default("root", true) }}'
    job: '{{ item.job }}'
    insertafter: '{{ item.insertafter | default(omit) }}'
  loop: "{{ cron_env_entries }}"
  loop_control:
    label: '{{ item.name }}'
  when: item.job is defined
  tags:
    - user_crontab


- name: (cron.yml) Set special time entries in user crontabs
  cron:
    name: '{{ item.name }}'
    special_time: '{{ item.special_time }}'
    user: '{{ item.user | default("root", true) }}'
    job: '{{ item.job }}'
    state: present
  loop: "{{ cron_user_special_time_entries }}"
  loop_control:
    label: '{{ item.name }}'
  when: item.job is defined
  tags:
    - user_crontab


- name: (cron.yml) Set normal entries in user crontabs
  cron:
    name: '{{ item.name }}'
    minute: '{{ item.minute | default(omit) }}'
    hour: '{{ item.hour | default("root", true) }}'
    day: '{{ day | default(omit) }}'
    weekday: '{{ item.weekday | default(omit) }}'
    month: '{{ item.month | default(omit) }}'
    job: '{{ item.job }}'
  loop: "{{ cron_user_entries }}"
  loop_control:
    label: '{{ item.name }}'
  when: item.job is defined
  tags:
    - user_crontab
