---
- name: Upgrade apt cache
  import_playbook: helpers/apt_cache_update.yaml

- name: Upgrade packages
  hosts: all

  tasks:

  - name: Apt upgrade all packages
    apt:
      name: "*"
      state: latest
    when: ansible_os_family == 'Debian'

  - name: Apt remove unused dependencies
    apt:
      autoremove: yes
    when: ansible_os_family == 'Debian'

  - name: Dnf upgrade all packages
    dnf:
      name: "*"
      state: latest
    when: ansible_os_family == 'RedHat'

  - name: Dnf remove unused dependencies
    dnf:
      autoremove: yes
    when: ansible_os_family == 'RedHat'

  - name: Zypper upgrade all packages
    zypper:
      name: '*'
      state: latest
      update_cache: yes
    when: ansible_os_family == 'Suse'