--- - name: create apt-cacher-ng user user: name: apt-cacher-ng home: /var/cache/apt-cacher-ng shell: /usr/sbin/nologin create_home: no system: yes state: present - name: prepare storage volume for /var/cache/apt-cacher-ng when: apt_cacher_ng_storage is defined vars: apt_cacher_ng_storage_override: dest: /var/cache/apt-cacher-ng owner: apt-cacher-ng group: apt-cacher-ng mode: '02755' storage_volume: "{{ apt_cacher_ng_storage | combine(apt_cacher_ng_storage_override) }}" include_role: name: "storage/{{ apt_cacher_ng_storage.type }}/volume" - name: install apt-cacher-ng apt: name: apt-cacher-ng state: present - name: fetch current remaps slurp: src: /etc/apt-cacher-ng/acng.conf register: apt_cacher_ng_config_data - name: fetch current backend files find: paths: /etc/apt-cacher-ng patterns: 'backends_*' recurse: no file_type: any register: apt_cacher_ng_backends_files - name: remove superflous remaps loop: "{{ (apt_cacher_ng_config_data.content | b64decode).splitlines() | select('match', '^Remap-') | map('regex_replace', '^Remap-([^:]*):.*$', '\\1') }}" lineinfile: path: /etc/apt-cacher-ng/acng.conf regexp: '^Remap-{{ item }}:.*' state: absent notify: restart apt-cacher-ng - name: remove superflous backend files loop: "{{ apt_cacher_ng_backends_files.files | map(attribute='path') | map('basename') | map('regex_replace', '^backends_(.*)$', '\\1') | difference(apt_cacher_ng_remaps | list) }}" file: path: "/etc/apt-cacher-ng/backends_{{ item }}" state: absent - name: add ansible config copy: content: | # ansible managed BindAddress: 127.0.0.1 ForceManaged: 1 {% for name, config in apt_cacher_ng_remaps.items() %} Remap-{{ name }}: {{ config.path }} ; file:backends_{{ name }} {% endfor %} dest: /etc/apt-cacher-ng/zzz_ansible.conf notify: restart apt-cacher-ng - name: create backend files loop: "{{ apt_cacher_ng_remaps | dict2items }}" loop_control: label: "{{ item.key }}" copy: content: | {% for backend in item.value.backends %} {{ backend }} {% endfor %} dest: "/etc/apt-cacher-ng/backends_{{ item.key }}" notify: restart apt-cacher-ng - name: configure admin auth lineinfile: path: /etc/apt-cacher-ng/security.conf regexp: '#\s*AdminAuth:' line: "AdminAuth: {{ apt_cacher_ng_admin_auth.username }}:{{ apt_cacher_ng_admin_auth.password }}" notify: restart apt-cacher-ng - name: configure nginx vhost vars: nginx_vhost: default: yes name: apt-cacher-ng template: generic hostnames: - "{{ apt_cacher_ng_hostname }}" locations: '/': proxy_pass: http://127.0.0.1:3142 include_role: name: nginx/vhost