- set_fact:
    dnf_log_files:
      - /var/log/dnf5.log
  when: dnf5

- set_fact:
    dnf_log_files:
      - /var/log/dnf.log
      - /var/log/dnf.rpm.log
      - /var/log/dnf.librepo.log
  when: not dnf5

- name: Check logging enabled
  block:
    - name: remove logfiles if exist
      file:
        path: "{{ item }}"
        state: absent
      loop: "{{ dnf_log_files }}"

    - name: Install sos package
      dnf:
        name: sos
        state: present
      register: dnf_result

    - name: Get status of logfiles
      stat:
        path: "{{ item }}"
      loop: "{{ dnf_log_files }}"
      register: stats

    - name: Verify logfile exists
      assert:
        that:
          - "item.stat.exists"
      loop: "{{ stats.results }}"
