# Update lists and upgrade packages.

- name: update apt package lists
  apt:
    update_cache: true
    cache_valid_time: 86400
  throttle: 3

- name: upgrade packages
  apt:
    upgrade: dist
    autoremove: true
    autoclean: true

- name: install etckeeper
  apt:
    name: etckeeper
    state: latest # noqa package-latest

- name: install extra packages from stable
  apt:
    name: "{{ extra_pkgs }}"
    state: latest # noqa package-latest
  when: extra_pkgs|length

- name: add {{ ansible_distribution_release }}-backports
  apt_repository:
    repo: >
      deb http://deb.debian.org/debian/ {{ ansible_distribution_release }}-backports
      main contrib non-free-firmware non-free
    state: present
    update_cache: true
  when: extra_pkgs_bpo|length

- name: install extra packages from backports
  apt:
    name: "{{ extra_pkgs_bpo }}"
    state: latest # noqa package-latest
    default_release: "{{ ansible_distribution_release }}-backports"
  when: extra_pkgs_bpo|length
