---
- name: Cron jobs for production machines
  block:
  - name: Backup database daily
    cron:
      name: "backup database"
      user: faf
      job: >-
        ( pg_dump --format=custom --file={{ faf_backup_dir }}/backup-$(date '+\%F').dump faf )
        >> /var/log/faf/db_backup.log 2>&1
      special_time: daily
      state: present

  - name: Delete old database backups
    cron:
      name: "delete old database backups"
      user: faf
      job: "find {{ faf_backup_dir }} -mtime {{ faf_old_backup_age }} -type f -delete"
      special_time: daily
      state: present

  - name: Pull associates
    cron:
      name: "cron for pull associates"
      user: faf
      job: "faf pull-associates -o fedora >> /var/log/faf/pull-associates.log 2>&1"
      special_time: daily
      state: present

  - 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 2>&1"
      special_time: daily
      state: present

  - name: Job for probable fixes in active Fedora releases
    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
    loop: "{{ rs_internal_fedora_vers }}"

  - name: Remove job for probable fixes in removed Fedora releases
    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
    loop: "{{ rs_internal_fedora_vers_removed }}"

  - 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

  - 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

  - name: Attach BZ bugs centos
    cron:
      name: "cron for attach BZ bugs centos"
      user: faf
      job: "faf attach-centos-bugs >> /var/log/faf/attach-centos-bugs.log 2>&1"
      special_time: daily
      state: present

  - name: Archive reports and attachments
    cron:
      name: "faf archive reports and attachments"
      user: faf
      job: "faf archive-reports -d >> /var/log/faf/archive-reports.log 2>&1"
      special_time: daily
      state: present
  when: env != 'staging'

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