---
- name: Merge extra_pkgs and extra_pkgs_bpo lists
  ansible.builtin.set_fact:
    extra_pkgs: "{{ extra_pkgs + lookup('vars', 'extra_pkgs' + item, default=[]) }}"
    extra_pkgs_bpo: "{{ extra_pkgs_bpo + lookup('vars', 'extra_pkgs_bpo' + item, default=[]) }}"
  loop: "{{ range(1, 11) | map('string') | list }}"

- name: Install extra packages from stable
  ansible.builtin.apt:
    name: "{{ extra_pkgs }}"
  when: extra_pkgs|length

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

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