blob: decbf6b074133659fbdcabe449cbada24c5f4f7c (
plain)
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
|
- name: Setup the main server
hosts: datagubbe.dev
become: true
vars:
jailbase: "/usr/local/jails"
jailset: "poolen/jails"
jails:
gubbhub:
name: gubbhub
ip: "2a01:4f9:2b:f05::2/64"
tags: gubbhub
additional_data_sets:
- gitdata
certificates:
- git.datagubbe.dev
haproxy_conf: |
frontend git-ssh from tcp
mode tcp
bind :2224
default_backend gubbhub
backend gubbhub from tcp
server srv 2a01:4f9:2b:f05::2:22
backend git.datagubbe.dev from http
server srv 2a01:4f9:2b:f05::2:80
hallosbacken:
name: hallosbacken
ip: "2a01:4f9:2b:f05::3/64"
tags: hallosbacken
additional_data_sets:
- wp_data
datagubbe:
name: datagubbe
ip: "2a01:4f9:2b:f05::4/64"
tags: datagubbe
certificates:
- datagubbe.dev
haproxy_conf: |
backend datagubbe from http
server srv 2a01:4f9:2b:f05::4:80
roles:
- pf
- jailhost
- role: jail
jail: "{{ jails.gubbhub }}"
tags: "{{ jails.gubbhub.tags }}"
- role: jail
jail: "{{ jails.hallosbacken }}"
- role: jail
jail: "{{ jails.datagubbe }}"
tasks:
- name: configure periodic to be less chatty
ansible.builtin.copy:
content: |
# i do not need to know this
daily_show_success=”NO”
weekly_show_success="NO"
monthly_show_success="NO"
# enable our certbot renew script
daily_renewcerts_enable="YES"
dest: /etc/periodic.conf
- name: install jq
community.general.pkgng:
name: "jq"
state: latest
- name: install haproxy
community.general.pkgng:
name: "haproxy"
state: latest
- name: create haproxy user
ansible.builtin.user:
name: haproxy
system: true
- name: config for haproxy
ansible.builtin.template:
src: haproxy.conf.j2
dest: /usr/local/etc/haproxy.conf
notify: reload haproxy
- name: enable haproxy service
community.general.sysrc:
name: haproxy_enable
value: "YES"
notify: start haproxy
- name: install certbot and nginx
community.general.pkgng:
name:
- security/py-certbot
- nginx
state: latest
- name: nginx config for certbot
ansible.builtin.template:
src: templates/nginx-certbot.conf.j2
dest: /usr/local/etc/nginx/nginx.conf
vars:
root: /var/www/html
- name: enable nginx
community.general.sysrc:
name: nginx_enable
value: "YES"
- name: start nginx
ansible.builtin.service:
name: nginx
state: reloaded
- name: create cert hook for haproxy
ansible.builtin.copy:
content: |
#! /usr/bin/env sh
mkdir -p /usr/local/etc/haproxy/certs
dir="$RENEWED_LINEAGE"
domain=`basename "$RENEWED_LINEAGE"`
cat $dir/fullchain.pem $dir/privkey.pem > /usr/local/etc/haproxy/certs/$domain.pem
chown -R haproxy:haproxy /usr/local/etc/haproxy
dest: /usr/local/etc/letsencrypt/renewal-hooks/deploy/create-haproxy-cert
mode: 755
- name: set needed certs
ansible.builtin.set_fact:
certificates: "{{ jails | dict2items | selectattr('value.certificates', 'defined') | map(attribute='value.certificates') | list | flatten }}"
- name: "obtain cert for {{ item }}"
shell:
cmd: |
certbot \
--non-interactive \
--email albert@acervin.com \
--agree-tos \
certonly \
--webroot \
--webroot-path /var/www/html \
-d '{{ item }}'
RENEWED_LINEAGE=/usr/local/etc/letsencrypt/live/{{item}} /usr/local/etc/letsencrypt/renewal-hooks/deploy/create-haproxy-cert
creates: /usr/local/etc/letsencrypt/live/{{ item }}
loop: "{{ certificates }}"
- name: create daily job for updating certs
ansible.builtin.copy:
src: ./10-renewcerts
dest: /usr/local/etc/periodic/daily/10-renewcerts
mode: 'a=rx,u=rwx'
- name: config for haproxy (with certs)
ansible.builtin.template:
src: haproxy.conf.j2
dest: /usr/local/etc/haproxy.conf
notify: reload haproxy
- name: Setup datagubbe
import_tasks: jails/datagubbe/tasks.yaml
vars:
jail: "{{ jails.datagubbe }}"
certs:
- /usr/local/etc/certs/datagubbe.dev.pem
tags: datagubbe-setup
- name: Setup the gubbhub
import_tasks: jails/gubbhub/tasks.yaml
vars:
jail: "{{ jails.gubbhub }}"
tags: gubbhub-setup
- name: Make sure packages are up to date
community.general.pkgng:
name: "*"
state: latest
handlers:
- name: reload haproxy
ansible.builtin.shell: /usr/local/etc/rc.d/haproxy configtest && /usr/local/etc/rc.d/haproxy reload
- name: start haproxy
ansible.builtin.service:
name: haproxy
state: started
- name: restart sshd in jail
jexec:
jail:
|