---
- name: Software setup
  hosts: all
  user: root

  handlers:
    - name: Dependency cleanup
      ansible.builtin.dnf:
        autoremove: true

  tasks:
    - name: Upgrade packages
      ansible.builtin.dnf:
        update_cache: true
        name: "*"
        state: latest

    - name: Install applications
      ansible.builtin.dnf:
        name: "{{ dnf_install }}"
        state: present
      when: dnf_install

    - name: Remove applications
      ansible.builtin.dnf:
        name: "{{ dnf_remove }}"
        state: absent
      when: dnf_remove
      notify: Dependency cleanup

    - name: Install apps from Flatpak
      community.general.flatpak:
        name: "{{ flatpak_install }}"
        state: present
      when: flatpak_install

    - name: Remove apps from Flatpak
      community.general.flatpak:
        name: "{{ flatpak_remove }}"
        state: absent
      when: flatpak_remove
