---
- name: Set the appropriate apt proxy URL for integration with AptCacherNG
  copy:
    dest: "{{ apt_path }}/apt.conf.d/00apt-cacher-ng"
    mode: 0600
    content: |
      Acquire::http { Proxy "http://{{ apt_cacher_endpoint }}:3142"; };

- name: Acquire a list of sources from /etc/apt/sources.list.d
  find:
    paths:
      - "{{ apt_path }}/sources.list.d"
  register: sources_files

- name: Configure /etc/apt/sources.list.d/* to use AptCacherNG
  replace:
    path: "{{ item.path }}"
    regexp: " https:\/\/"
    replace: " http://HTTPS///"
  loop: "{{ sources_files.files }}"
  loop_control:
    label: "{{ item.path }}"

- name: Configure /etc/apt/sources.list to use AptCacherNG
  replace:
    path: "{{ apt_path }}/sources.list"
    regexp: " https:\/\/"
    replace: " http://HTTPS///"
