---
- name: setup pinning
  copy: dest=/etc/apt/preferences.d/apt-pinning src=apt-pinning owner=root group=root mode=0644

- name: rm sources.list
  file: dest=/etc/apt/sources.list state=absent
  register: aptup1

- apt_repository: repo='deb http://ftp.debian.org/debian {{item}} main contrib non-free' state=present
  with_items:
    - stable
    - testing
    - unstable
  register: aptup2

- apt: update_cache=yes
  when: aptup1.changed or aptup2.changed


---
- name: install packages required by apt_repository
  apt: package={{item}} state=present
  with_items:
    - python-apt

- name: setup pinning
  copy: dest=/etc/apt/preferences.d/apt-pinning src=apt-pinning owner=root group=root mode=0644

- name: rm sources.list
  file: dest=/etc/apt/sources.list state=absent
  register: aptup1

- apt_repository: repo='deb http://ftp.debian.org/debian {{item}} main contrib non-free' state=present
  with_items:
    - stable
    - testing
    - unstable
  register: aptup2

- apt: update_cache=yes
  when: aptup1.changed or aptup2.changed


Install python-apt before using apt_repository
Install python-apt before using apt_repository
