---
- name: Create retrace-server reposync cron jobs for active Fedora versions
  loop: "{{ rs_internal_fedora_vers | product(rs_internal_arch_list) | list }}"
  when: "{{ item[1] != 'source' }}"
  cron:
    name: "rs reposync fedora {{ item[0] }} {{ item[1] }}"
    user: retrace
    job: "/usr/bin/retrace-server-reposync fedora {{ item[0] }} {{ item[1] }} >> /var/log/retrace-server/reposync_error.log 2>&1"
    special_time: daily
    state: present

- name: Remove retrace-server reposync cron jobs of removed Fedora versions
  loop: "{{ rs_internal_fedora_vers_removed | product(rs_internal_arch_list) | list }}"
  when: "{{ item[1] != 'source' }}"
  cron:
    name: "rs reposync fedora {{ item[0] }} {{ item[1] }}"
    user: retrace
    job: "/usr/bin/retrace-server-reposync fedora {{ item[0] }} {{ item[1] }} >> /var/log/retrace-server/reposync_error.log 2>&1"
    special_time: daily
    state: absent

- name: Create retrace-server reposync cron jobs for CentOS
  cron:
    name: "rs reposync centos {{ item }} x86_64"
    user: retrace
    job: "/usr/bin/retrace-server-reposync centos {{ item }} x86_64 >> /var/log/retrace-server/reposync_error.log 2>&1"
    special_time: daily
    state: present
  loop: "{{ rs_internal_centos_vers }}"

- name: Create retrace-server cleanup cron job
  cron:
    name: "retrace-server-cleanup"
    user: retrace
    job: "/usr/bin/retrace-server-cleanup >> /var/log/retrace-server/cleanup_error.log 2>&1"
    special_time: daily
    state: present

- name: Create cron job for retrace-server
  cron:
    name: "podman prune"
    user: retrace
    job: "/usr/bin/podman system prune --all --force >> /var/log/retrace-server/podman_prune.log 2>&1"
    special_time: daily
    state: present
