---
- name: Clean up unused packages and temporary files
  hosts: all
  become: true
  tasks:
    - name: Autoremove unused packages
      apt:
        autoremove: yes
      when: ansible_os_family == "Debian"

    - name: Clean apt cache
      apt:
        autoclean: yes
      when: ansible_os_family == "Debian"

    - name: Clear temporary files
      file:
        path: /tmp
        state: absent
      ignore_errors: true

    - name: Recreate /tmp directory
      file:
        path: /tmp
        state: directory
        mode: '1777'
