- name: install backports apt list template: src: backports.list.j2 dest: /etc/apt/sources.list.d/backports.list # do this from a template to fully remove any other lines in the file. - name: remove obsolete apt lists file: path=/etc/apt/sources.list.d/{{ item }}-backports.list state=absent with_items: - jessie - stretch - name: remove obsolete apt list entries lineinfile: path=/etc/apt/sources.list regexp="{{ item }}-backports" state=absent with_items: - jessie - stretch - name: update apt cache apt: update_cache=yes changed_when: false