---
- name: No backports config in default sources.list
  ansible.builtin.lineinfile:
    dest: /etc/apt/sources.list
    regexp: "backports"
    state: absent
  tags:
    - apt

- name: Backports sources list is installed
  ansible.builtin.template:
    src: '{{ ansible_distribution_release }}_backports.list.j2'
    dest: /etc/apt/sources.list.d/backports.list
    force: true
    mode: "0640"
  register: apt_backports_list
  tags:
    - apt

- name: Archived backport are accepted (jessie)
  ansible.builtin.lineinfile:
    dest: '/etc/apt/apt.conf.d/99no-check-valid-until'
    line: 'Acquire::Check-Valid-Until no;'
    create: yes
    state: present
  tags:
    - apt
  when: ansible_distribution_release == "jessie"

- name: Apt update
  ansible.builtin.apt:
    update_cache: yes
  tags:
    - apt
  when: apt_backports_list is changed
