---
- name: Update sources list
  ansible.builtin.template:
    src: 'sources.list.j2'
    dest: '/etc/apt/sources.list'
    owner: 'root'
    group: 'root'
    mode: '0644'
  register: res

- name: Upgrade all packages to the latest version in testing
  ansible.builtin.apt:
    upgrade: dist
    update_cache: yes
    cache_valid_time: 3600
  when: 'res.changed'

- name: Clean up unused packages
  ansible.builtin.apt:
    autoremove: yes
  when: 'res.changed'
