-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadguard-home-debian.yml
194 lines (164 loc) · 5.45 KB
/
adguard-home-debian.yml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env ansible-playbook
---
- name: AdGuard Home for Debian (and Ubuntu)
hosts: localhost
vars:
home_port: 80
dns_port: 53
tmp_dir: "/tmp/ansible/AdGuardHome"
connection: local
gather_facts: false
become: true
tasks:
- name: Gather only facts returned by os_family and distribution
ansible.builtin.setup:
gather_subset:
- "!all"
- "!min"
- os_family
- distribution
- name: Ensure that OS family is Debian
ansible.builtin.assert:
that:
- ansible_os_family == "Debian"
quiet: true
- name: Gather facts on listening ports
community.general.listen_ports_facts:
- name: Check if a process listen on port 3000/tcp
ansible.builtin.set_fact:
conf_port_conflict: "{{ item }}"
loop: "{{ tcp_listen }}"
when: item.port == 3000
- name: Check if a process listen on port {{ home_port }}/tcp
ansible.builtin.set_fact:
home_port_conflict: "{{ item }}"
loop: "{{ tcp_listen }}"
when: item.port == home_port
- name: Ensure that configuration and home ports are available
ansible.builtin.assert:
that:
- conf_port_conflict is undefined
- home_port_conflict is undefined
quiet: true
- name: Check if a process listen on port {{ dns_port }}/udp
ansible.builtin.set_fact:
dns_port_conflict: "{{ item }}"
loop: "{{ udp_listen }}"
when: item.port == dns_port
- name: "Handle Ubuntu systemd-resolved if needed \
(https://adguard-dns.io/kb/adguard-home/faq/#bindinuse)"
block:
- name: Create /etc/systemd/resolved.conf.d
ansible.builtin.file:
path: /etc/systemd/resolved.conf.d
state: directory
- name: Edit /etc/systemd/resolved.conf.d/adguardhome.conf
ansible.builtin.lineinfile:
path: /etc/systemd/resolved.conf.d/adguardhome.conf
line: "{{ item }}"
create: true
loop:
- "[Resolve]"
- "DNS=127.0.0.1"
- "DNSStubListener=no"
- name: Backup /etc/resolv.conf
ansible.builtin.copy:
src: /etc/resolv.conf
dest: /etc/resolv.conf.backup
- name: "Create a symbolic link /etc/resolv.conf to \
/run/systemd/resolve/resolv.conf"
ansible.builtin.file:
src: /run/systemd/resolve/resolv.conf
dest: /etc/resolv.conf
state: link
- name: Restart systemd-resolved service
ansible.builtin.service:
name: systemd-resolved
state: restarted
enabled: true
- name: Gather facts on listening ports
community.general.listen_ports_facts:
- name: Check if a process listen on port 53/udp
ansible.builtin.set_fact:
dns_port_issue: "{{ item }}"
loop: "{{ udp_listen }}"
when: item.port == 53
- name: Check if a process listen on port 53/udp
ansible.builtin.set_fact:
dns_port_conflict: null
when: dns_port_issue is undefined
when:
- ansible_distribution == "Ubuntu"
- dns_port == 53
- dns_port_conflict is defined
- dns_port_conflict.user == "systemd-resolve"
- name: Ensure that dns port is available
ansible.builtin.assert:
that:
- dns_port_conflict is undefined or not dns_port_conflict
quiet: true
- name: Update installed packages
ansible.builtin.apt:
name: "*"
state: latest
update_cache: true
clean: true
- name: Install ufw package
ansible.builtin.apt:
name: ufw
state: latest
- name: Create {{ tmp_dir }}
ansible.builtin.file:
path: "{{ tmp_dir }}"
state: directory
- name: Download AdGuardHome installation script
ansible.builtin.get_url:
url: "https://raw.githubusercontent.com/AdguardTeam/\
AdGuardHome/master/scripts/install.sh"
dest: "{{ tmp_dir }}"
mode: "0500"
- name: Execute {{ tmp_dir }}/install.sh
ansible.builtin.shell:
cmd: "{{ tmp_dir }}/install.sh"
- name: Reload ufw and allow adguard-install port
community.general.ufw:
rule: allow
proto: tcp
port: 3000
comment: "allow-adguard-install"
state: reloaded
- name: "Wait to configure AdGuard Home through the web interface \
listening on 0.0.0.0:3000"
ansible.builtin.wait_for:
host: 0.0.0.0
port: 3000
delay: 10
state: stopped
- name: Reload ufw and delete adguard-install port
community.general.ufw:
delete: true
rule: allow
proto: tcp
port: 3000
comment: "allow-adguard-install"
state: reloaded
- name: Enable ufw and allow adguard-home port
community.general.ufw:
rule: allow
proto: tcp
port: "{{ home_port }}"
comment: "allow-adguard-home"
state: enabled
- name: Enable ufw and allow adguard-dns port
community.general.ufw:
rule: allow
proto: udp
port: "{{ dns_port }}"
comment: "allow-adguard-dns"
state: enabled
- name: Remove dependencies that are no longer required
ansible.builtin.apt:
autoremove: true
- name: Remove useless packages from the cache
ansible.builtin.apt:
autoclean: true