~xenrox/ansible

ref: 85bb5f61932c4851d513bb56486460511c316db6 ansible/roles/srht/tasks/main.yml -rw-r--r-- 6.6 KiB
85bb5f61Thorben Günther vaultwarden: Config update 2 months ago
                                                                                
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
296
297
298
299
300
301
302
303
---
- name: Get secrets
  ansible.builtin.set_fact:
    srht_secrets: "{{ lookup('community.hashi_vault.hashi_vault', 'ansible/data/srht') }}"

- name: Get gpg secrets
  ansible.builtin.set_fact:
    gpg_secrets: "{{ lookup('community.hashi_vault.hashi_vault', 'ansible/data/srht-gpg') }}"

- name: Get minio secrets
  ansible.builtin.set_fact:
    minio_secrets: "{{ lookup('community.hashi_vault.hashi_vault', 'ansible/data/minio') }}"

- name: Get email secrets
  ansible.builtin.set_fact:
    email_secrets: "{{ lookup('community.hashi_vault.hashi_vault', 'ansible/data/email') }}"

- name: install srht packages
  community.general.pacman:
    name: "{{ srht_packages }}"
    state: present

- name: create srht config path
  ansible.builtin.file:
    path: /etc/sr.ht
    state: directory
    owner: root
    group: root
    mode: 0755

- name: configure srht
  ansible.builtin.template:
    src: config.ini.j2
    dest: /etc/sr.ht/config.ini
    owner: root
    group: root
    mode: 0644
  notify: restart srht

- name: Deposit GPG private key
  ansible.builtin.template:
    src: sourcehut.priv.j2
    dest: /etc/sr.ht/sourcehut.priv
    owner: root
    group: root
    mode: 0644

- name: Deposit GPG public key
  ansible.builtin.template:
    src: sourcehut.pub.j2
    dest: /etc/sr.ht/sourcehut.pub
    owner: root
    group: root
    mode: 0644

- name: create systemd unit override path for git
  ansible.builtin.file:
    path: "/etc/systemd/system/{{ item }}.d"
    state: directory
    owner: root
    group: root
    mode: 0755
  with_items:
    - git.sr.ht.service
    - git.sr.ht-api.service
    - git.sr.ht-webhooks.service
    - git.sr.ht-periodic.service

- name: install systemd unit override file
  ansible.builtin.copy:
    src: override.conf
    dest: "/etc/systemd/system/{{ item }}.d/override.conf"
    owner: root
    group: root
    mode: 0644
  with_items:
    - git.sr.ht.service
    - git.sr.ht-api.service
    - git.sr.ht-webhooks.service
    - git.sr.ht-periodic.service

- name: Create db user
  community.general.postgresql_user:
    name: srht
    password: "{{ srht_secrets['psql_password'] }}"
  become: true
  become_user: postgres
  no_log: true

- name: Create meta db
  community.general.postgresql_db:
    db: srht-meta
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-meta

- name: Create builds db
  community.general.postgresql_db:
    db: srht-builds
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-builds

- name: Create git db
  community.general.postgresql_db:
    db: srht-git
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-git

- name: Create hub db
  community.general.postgresql_db:
    db: srht-hub
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-hub

- name: Create lists db
  community.general.postgresql_db:
    db: srht-lists
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-lists

- name: Create man db
  community.general.postgresql_db:
    db: srht-man
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-man

- name: Create paste db
  community.general.postgresql_db:
    db: srht-paste
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-paste

- name: Create todo db
  community.general.postgresql_db:
    db: srht-todo
    owner: srht
  become: true
  become_user: postgres
  notify: Init srht-todo

- name: Build qemu docker image
  community.docker.docker_image:
    build:
      path: /var/lib/images
      dockerfile: qemu/Dockerfile
    name: qemu
    source: build
  notify: Prune images

- name: start and enable srht services
  ansible.builtin.systemd:
    name: "{{ item }}"
    enabled: true
    state: started
    daemon_reload: true
  with_items: "{{ srht_services }}"

- name: add archlinux rebuild cronjob
  ansible.builtin.cron:
    name: arch rebuild
    state: present
    user: root
    job: 'chronic /usr/bin/builds.sr.ht/submit_image_build -n "Arch rebuild" -u "https://builds.xenrox.net" -p "/var/lib/images/builds" archlinux'
    hour: "9"
    minute: "0"

- name: add alpine rebuild cronjob
  ansible.builtin.cron:
    name: alpine rebuild
    state: present
    user: root
    job: 'chronic /usr/bin/builds.sr.ht/submit_image_build -n "Alpine rebuild" -u "https://builds.xenrox.net" -p "/var/lib/images/builds" alpine/edge'
    hour: "9"
    minute: "30"

- name: copy nginx conf
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: /etc/nginx/nginx.d
    owner: root
    group: root
    mode: 0644
  with_fileglob:
    - files/nginx/*
  notify:
    - restart nginx

- name: Install nginx runenr conf
  ansible.builtin.template:
    src: runner.conf.j2
    dest: /etc/nginx/nginx.d/runner.conf
    owner: root
    group: root
    mode: 0644
  notify: restart nginx

- name: Copy nginx snippets
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: /etc/nginx/snippets
    owner: root
    group: root
    mode: 0755
  with_items:
    - graphql.conf
    - srht.conf
    - srht_robots.txt
    - srht_web.conf
  notify: restart nginx

- name: copy api key
  ansible.builtin.template:
    src: image-refresh-token.j2
    dest: /etc/sr.ht/image-refresh-token
    owner: root
    group: root
    mode: 0644

- name: setup image build files
  ansible.builtin.git:
    repo: https://git.xenrox.net/~xenrox/builds
    dest: /var/lib/images/builds
    version: master

- name: add deploy user to buildsrht group
  ansible.builtin.user:
    name: deploy
    append: true
    groups: buildsrht

- name: Set image dir permissions
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    owner: buildsrht
    group: buildsrht
    mode: 0775
  with_items:
    - /var/lib/images/archlinux
    - /var/lib/images/alpine/edge

- name: Create runner log dir
  ansible.builtin.file:
    path: /var/log/srht-runner
    state: directory
    owner: runner
    group: runner
    mode: 0755

- name: Create git repo dir
  ansible.builtin.file:
    path: /var/lib/git
    state: directory
    owner: git
    group: git
    mode: 0755

- name: Set git user shell
  ansible.builtin.user:
    name: git
    shell: /bin/bash

- name: Set logs owner to git
  ansible.builtin.file:
    path: /var/log/{{ item }}
    owner: gitsrht
    group: gitsrht
    mode: 0666
  with_items:
    - gitsrht-dispatch
    - gitsrht-keys
    - gitsrht-shell
    - gitsrht-update-hook

- name: Install fcgiwrap
  community.general.pacman:
    name: fcgiwrap
    state: present

- name: Enable and start fcgiwrap
  ansible.builtin.systemd:
    name: fcgiwrap.socket
    enabled: true
    state: started

  # For SSH access
- name: Create builds user
  ansible.builtin.user:
    name: builds
    shell: /usr/bin/bash