summaryrefslogtreecommitdiff
path: root/roles/apt-cacher-ng/tasks/main.yml
diff options
context:
space:
mode:
Diffstat (limited to 'roles/apt-cacher-ng/tasks/main.yml')
-rw-r--r--roles/apt-cacher-ng/tasks/main.yml58
1 files changed, 58 insertions, 0 deletions
diff --git a/roles/apt-cacher-ng/tasks/main.yml b/roles/apt-cacher-ng/tasks/main.yml
index bfe05383..eb1620cc 100644
--- a/roles/apt-cacher-ng/tasks/main.yml
+++ b/roles/apt-cacher-ng/tasks/main.yml
@@ -24,3 +24,61 @@
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
+ 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