# Update lists and upgrade packages.

- name: Update apt package lists
  ansible.builtin.apt:
    update_cache: true
    cache_valid_time: 86400

- name: Try to upgrade packages
  block:
    - name: Upgrade packages
      ansible.builtin.apt:
        upgrade: dist
        autoremove: true
        autoclean: true
  rescue:
    - name: Looks like dpkg was interrupted, configure manually
      ansible.builtin.command:
        cmd: dpkg --configure -a
      changed_when: true
    - name: Try again to upgrade packages
      ansible.builtin.apt:
        upgrade: dist
        autoremove: true
        autoclean: true

- name: Install etckeeper
  ansible.builtin.apt:
    name: etckeeper
