- name: server | system_setup | install cron (archlinux)
  package:
    name: "cronie"
    state: latest
  when: ansible_distribution == "Archlinux"

- name: server | system_setup | cron (VM)
  tags: cron
  cron:
    name: "{{ item.title }}"
    user: root
    hour: "{{ item.hour }}"
    minute: "{{ item.minute }}"
    job: "{{ item.job }}"
    state: absent
  when:
   - ansible_virtualization_role == "NA" or ansible_virtualization_role == "guest"
   - ansible_virtualization_type == "kvm"
  loop:
    - { title: "Backup", job: "/root/bin/backup_vps.bash", hour: 1, minute: 0 }

- name: server | system_setup | cron (non VM)
  tags: cron
  cron:
    name: "{{ item.title }}"
    user: root
    hour: "{{ item.hour }}"
    minute: "{{ item.minute }}"
    job: "{{ item.job }}"
    state: absent
  when: ansible_virtualization_role != "guest" or ansible_virtualization_type != "kvm"
  loop:
    - { title: "Backup", job: "/root/bin/backup_vps.bash", hour: 1, minute: 0 }

- name: server | system_setup | cron (generic)
  tags: cron
  cron:
    name: "{{ item.title }}"
    user: root
    hour: "{{ item.hour }}"
    minute: "{{ item.minute }}"
    job: "{{ item.job }}"
  loop:
    - { title: "Send me a list of upgradeable packages", job: "{{ check_update_cmd }}", hour: 0, minute: 0 }