blob: df47ee9e64f0e6e3095bdf830d5dc722a3ef2ad2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
---
- 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
|