-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
295 lines (256 loc) · 7.67 KB
/
main.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
---
- hosts: rpihole
tasks:
- name: Update all installed packages using APT module
apt:
name: '*'
state: latest
update_cache: yes
only_upgrade: yes
become: yes
- name: Install dependencies
apt:
update_cache: yes
name:
- vim
- nmap
- tmux
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
- python3-pip
- dnsutils
- libpam-google-authenticator
- expect
state: present
become: yes
- name: Add an docker apt signing key
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
keyring: /usr/share/keyrings/docker-archive-keyring.gpg
become: yes
- name: add docker repository to apt
apt_repository:
repo: deb [arch=armhf signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian buster stable
state: present
become: yes
- name: Add an syncthing apt signing key
apt_key:
url: https://syncthing.net/release-key.txt
state: present
become: yes
- name: add syncthing repository
apt_repository:
repo: deb https://apt.syncthing.net/ syncthing stable
state: present
become: yes
- name: Install Docker & syncthing
apt:
update_cache: yes
name:
- docker-ce
- docker-ce-cli
- containerd.io
- syncthing
state: present
become: yes
- name: Docker is running properly
service:
name: docker
state: started
enabled: yes
daemon_reload: yes
become: yes
- name: Install Docker Compose
pip:
name: docker-compose
become: yes
- name: Set LANG
lineinfile:
path: /etc/default/locale
regexp: "^LANG="
line: LANG=en_US.UTF-8
become: yes
- name: Set LC_ALL and LANGUAGE
blockinfile:
path: /etc/default/locale
block: |
LC_ALL=en_US.UTF-8
LANGUAGE=en_US.UTF-8
become: yes
- name: Disable en_GB
lineinfile:
path: /etc/locale.gen
regexp: "^en_GB.UTF-8 UTF-8"
line: "# en_GB.UTF-8 UTF-8"
backrefs: yes
register: dis_en_GB
become: yes
- name: Enable en_US
lineinfile:
path: /etc/locale.gen
regexp: "^# en_US.UTF-8 UTF-8"
line: en_US.UTF-8 UTF-8
backrefs: yes
register: ena_en_US
become: yes
- name: Generate locale
command: locale-gen
when: dis_en_GB.changed or ena_en_US.changed
become: yes
- name: Set localtime
file:
src: /usr/share/zoneinfo/{{ timezone }}
dest: /etc/localtime
state: link
become: yes
- name: Create pihole directory
file:
path: "/home/{{ ansible_user }}/pihole"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
mode: 0755
- name: Copy pihole docker-compose file with owner and permissions
copy:
src: "{{ playbook_dir }}/templates/docker-compose.yml"
dest: /home/{{ ansible_user }}/pihole/
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0755
- name: Tear down existing services
docker_compose:
project_src: /home/{{ ansible_user }}/pihole/
state: absent
become: yes
- name: Create and start services
docker_compose:
project_src: /home/{{ ansible_user }}/pihole/
register: output
become: yes
- name: Create ngrok directory
file:
path: "/home/{{ ansible_user }}/ngrok.d"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
state: directory
mode: 0755
- name: Extract foo.tgz into /var/lib/foo
unarchive:
src: https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
dest: /home/{{ ansible_user }}/ngrok.d/
remote_src: yes
- name: check ngrok conf done
stat:
path: /home/{{ ansible_user }}/.ngrok2/
register: ngrok_conf_dir
- name: set ngrok auth token
command: "/home/{{ ansible_user }}/ngrok.d/ngrok authtoken {{ ngrok_auth_token }}"
when: not ngrok_conf_dir.stat.exists
- name: Setup ngrok service
template:
src: "{{ playbook_dir }}/templates/ngrok_service.j2"
dest: /lib/systemd/system/ngrok.service
mode: 0644
become: yes
- name: Download syncthing service
get_url:
url: https://raw.githubusercontent.com/syncthing/syncthing/main/etc/linux-systemd/system/syncthing%40.service
dest: /lib/systemd/system/syncthing@service
mode: 0644
become: yes
- name: Enable & start syncthing
service:
name: syncthing@{{ ansible_user }}.service
state: started
enabled: yes
daemon_reload: yes
become: yes
- name: Copy check ngrok flag systemd timer
copy:
src: "{{ playbook_dir }}/templates/check-ngrok-flag.timer"
dest: /lib/systemd/system/
owner: root
group: root
mode: 0644
become: yes
- name: Copy check ngrok flag script
copy:
src: "{{ playbook_dir }}/scripts/trigger_ngrok.sh"
dest: "/home/{{ ansible_user }}/ngrok.d"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0700
- name: Setup check ngrok flag service
template:
src: "{{ playbook_dir }}/templates/check-ngrok-flag.j2"
dest: /lib/systemd/system/check-ngrok-flag.service
mode: 0644
become: yes
- name: Start check ngrok flag timer
service:
name: check-ngrok-flag.timer
state: started
enabled: yes
daemon_reload: yes
become: yes
- name: Comment sshd challenge line
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^ChallengeResponseAuthentication no"
line: "#ChallengeResponseAuthentication no"
backrefs: true
become: yes
- name: Disable ssh X11 forwarding
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^X11Forwarding yes"
line: "X11Forwarding no"
backrefs: true
become: yes
- name: Hardening
blockinfile:
path: /etc/ssh/sshd_config
validate: /usr/sbin/sshd -T -f %s
block: |
PermitRootLogin no
MaxAuthTries 3
MaxSessions 5
PasswordAuthentication no
PubkeyAuthentication yes
Port {{ ssh_port_number }}
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
register: sshd
become: yes
- name: 2fa ssh conf
blockinfile:
path: /etc/pam.d/sshd
block: |
auth required pam_google_authenticator.so
become: yes
- name: check google authenticator conf done
stat:
path: /home/{{ ansible_user }}/.google_authenticator
register: fa2_conf
- name: Setup google authenticator 2fa
script: "{{ playbook_dir }}/scripts/2fa_setup.exp"
when: not fa2_conf.stat.exists
- name: Allow ssh pub key
authorized_key:
user: "{{ ansible_user }}"
key: "{{ lookup('file', public_key_path) }}"
register: ssh_key
- name: output 2fa keys
command: cat /home/{{ ansible_user }}/.google_authenticator
when: not fa2_conf.stat.exists
- name: Restart sshd
service:
name: sshd
state: restarted
daemon_reload: yes
when: sshd.changed or ssh_key.changed or not fa2_conf.stat.exists
become: yes