- name: Configure FreshRSS automatic feed updates
  block:
    - name: Create cron job for feed updates
      ansible.builtin.cron:
        name: FreshRSS feed actualization
        minute: "*/15"
        hour: "*"
        day: "*"
        month: "*"
        weekday: "*"
        user: "{{ freshrss_sys_user }}"
        job: "/usr/bin/php {{ freshrss_install_path }}/app/actualize_script.php > /dev/null 2>&1"
        state: present

    - name: Create systemd timer for feed updates (alternative to cron)
      ansible.builtin.template:
        src: templates/freshrss-update.timer.j2
        dest: /etc/systemd/system/freshrss-update.timer
        owner: root
        group: root
        mode: "0644"
      when: freshrss_use_systemd_timer | default(false)

    - name: Create systemd service for feed updates
      ansible.builtin.template:
        src: templates/freshrss-update.service.j2
        dest: /etc/systemd/system/freshrss-update.service
        owner: root
        group: root
        mode: "0644"
      when: freshrss_use_systemd_timer | default(false)

    - name: Enable systemd timer for feed updates
      ansible.builtin.systemd_service:
        name: freshrss-update.timer
        enabled: true
        state: started
        daemon_reload: true
      when: freshrss_use_systemd_timer | default(false)
