---

- name: backup database
  cron:
    name: "backup database"
    user: faf
    job: "( pg_dump -Fc faf > /srv/faf/db-backup/backup-$(date '+\\%F').dump ) >> /var/log/faf/db_backup.log 2>&1"
    special_time: daily
    state: present

- name: delete old database backups
  cron:
    name: "delete database backups older than X days"
    user: faf
    job: "find /srv/faf/db-backup/ -mtime +14 -type f -delete"
    special_time: daily
    state: present

- name: match unknown packages
  cron:
    name: "match unknown packages"
    user: faf
    job: "faf match-unknown-packages -d >> /var/log/faf/match-unknown-packages.log 2>&1"
    special_time: daily
    state: present

- name: pull releases, components and associates
  cron:
    name: "cron for {{ item.what }} {{ item.distro }}"
    user: faf
    job: "faf {{ item.what }} -o {{ item.distro }} -d >> /var/log/faf/{{ item.what }}-{{ item.distro }}.log 2>&1"
    special_time: daily
    state: present
  when: not devel
  with_items:
    - { what: "pull-releases", distro: "fedora" }
    - { what: "pull-components", distro: "fedora" }
    - { what: "find-components", distro: "fedora" }
    - { what: "pull-releases", distro: "centos" }
    - { what: "pull-components", distro: "centos" }
    - { what: "find-components", distro: "centos" }

- name: pull associates
  cron:
    name: "cron for pull associates for f{{ item }}"
    user: faf
    job: "faf pull-associates -o fedora --opsys-release {{ item }} >> /var/log/faf/pull-associates-f{{ item }}.log 2>&1"
    special_time: monthly
    state: present
  when: not devel
  with_items:
    - "28"
    - "29"
    - "30"

- name: remove obsolete pull associates
  cron:
    name: "cron for pull associates for f{{ item }}"
    user: faf
    job: "faf pull-associates -o fedora --opsys-release {{ item }} >> /var/log/faf/pull-associates-f{{ item }}.log 2>&1"
    special_time: monthly
    state: absent
  when: not devel
  with_items:
    - "24"
    - "25"
    - "26"
    - "27"

- name: koops_to_xorg.py
  cron:
    name: "koops_to_xorg.py"
    user: faf
    job: "/etc/faf/koops_to_xorg.py >> /var/log/faf/koops-to-xorg.log"
    special_time: daily
    state: present
  when: not devel

- name: probable fixes
  cron:
    name: "cron for probable fixes for f{{ item }}"
    user: faf
    job: "faf mark-probably-fixed -o fedora --opsys-release {{ item }} >> /var/log/faf/mark-probably-fixed-f{{ item }}.log 2>&1"
    special_time: daily
    state: present
  when: not devel
  with_items:
    - "28"
    - "29"
    - "30"

- name: remove obsolete probable fixes
  cron:
    name: "cron for probable fixes for f{{ item }}"
    user: faf
    job: "faf mark-probably-fixed -o fedora --opsys-release {{ item }} >> /var/log/faf/mark-probably-fixed-f{{ item }}.log 2>&1"
    special_time: daily
    state: absent
  when: not devel
  with_items:
    - "24"
    - "25"
    - "26"
    - "27"

- name: update BZ bugs fedora
  cron:
    name: "cron for update BZ bugs fedora"
    user: faf
    job: "faf update-bugs -db fedora-bugzilla >> /var/log/faf/update-bugs.log 2>&1"
    special_time: daily
    state: present
  when: not devel

- name: update BZ bugs centos
  cron:
    name: "cron for update BZ bugs centos"
    user: faf
    job: "faf update-bugs -db centos-mantisbt >> /var/log/faf/update-bugs-centos.log 2>&1"
    special_time: daily
    state: present
  when: not devel

- name: attach BZ bugs centos
  cron:
    name: "cron for attach BZ bugs centos"
    user: faf
    job: "faf update-bugs -db centos-mantisbt >> /var/log/faf/update-bugs-centos.log 2>&1"
    special_time: daily
    state: present
  when: not devel

- name: install cron for deleting old archives
  cron: name="rotate_faf_archives" special_time="daily" job="find '/srv/faf/reports/archive/' -type f -name '*.tar.xz' -mtime '{{archive_age}}' -delete" user="faf"

- name: install faf cron for deleting old invalid reports
  cron: name="delete-old-invalid-reports" special_time="daily" job="find '/srv/faf/reports/deferred/' -type -f -mtime '{{ deferred_age }}' -delete" user="faf"

- name: install faf cron for deleting saved reports
  cron: name="delete-old-invalid-reports" special_time="daily" job="find '/srv/faf/reports/saved/' -type -f -mtime '{{ deferred_age }}' -delete" user="faf"
