blob: abbf527d9d540eb254e3fc18930d90b277d36416 (
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
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
|
---
title: 'Migrating privatebin from NixOS to Debian'
description: 'How I deploy privatebin with ansible'
date: '2024-11-17'
tags:
- ansible
- privatebin
---
## Introduction
I am migrating several services from a NixOS server (myth.adyxax.org) to a Debian server (lore.adyxax.org). Here is how I performed the operation for my self hosted [privatebin](https://privatebin.info/) served from paste.adyxax.org.
## Ansible role
### Meta
The `meta/main.yaml` contains the role dependencies:
``` yaml
---
dependencies:
- role: 'borg'
- role: 'nginx'
- role: 'podman'
```
### Tasks
The `tasks/main.yaml` file only creates a data directory and drops a configuration file. All the heavy lifting is then done by calling other roles:
``` yaml
---
- name: 'Make privatebin data directory'
file:
path: '/srv/privatebin'
owner: '65534'
group: '65534'
mode: '0750'
state: 'directory'
- name: 'Deploy privatebin configuration file'
copy:
src: 'privatebin.conf.php'
dest: '/etc/'
owner: 'root'
mode: '0444'
notify: 'restart privatebin'
- include_role:
name: 'podman'
tasks_from: 'container'
vars:
container:
cmd: ['--config-path', '/srv/cfg/conf.php']
name: 'privatebin'
env_vars:
- name: 'PHP_TZ'
value: 'Europe/Paris'
- name: 'TZ'
value: 'Europe/Paris'
image: '{{ versions.privatebin.image }}:{{ versions.privatebin.tag }}'
publishs:
- container_port: '8080'
host_port: '8082'
ip: '127.0.0.1'
volumes:
- dest: '/srv/cfg/conf.php:ro'
src: '/etc/privatebin.conf.php'
- dest: '/srv/data'
src: '/srv/privatebin'
- include_role:
name: 'nginx'
tasks_from: 'vhost'
vars:
vhost:
name: 'privatebin'
path: 'roles/paste.adyxax.org/files/nginx-vhost.conf'
- include_role:
name: 'borg'
tasks_from: 'client'
vars:
client:
jobs:
- name: 'data'
paths:
- '/srv/privatebin'
name: 'privatebin'
server: '{{ paste_adyxax_org.borg }}'
```
### Handlers
There is a single handler:
``` yaml
---
- name: 'restart privatebin'
service:
name: 'podman-privatebin'
state: 'restarted'
```
### Files
First there is my privatebin configuration, fairly simple:
``` php
;###############################################################################
;# \_o< WARNING : This file is being managed by ansible! >o_/ #
;# ~~~~ ~~~~ #
;###############################################################################
[main]
discussion = true
opendiscussion = false
password = true
fileupload = true
burnafterreadingselected = false
defaultformatter = "plaintext"
sizelimit = 10000000
template = "bootstrap"
notice = "Note: This is a personal sharing service: Data may be deleted anytime. Don't share illegal, unethical or morally reprehensible content."
languageselection = true
zerobincompatibility = false
[expire]
default = "1week"
[expire_options]
5min = 300
10min = 600
1hour = 3600
1day = 86400
1week = 604800
1month = 2592000
1year = 31536000
[formatter_options]
plaintext = "Plain Text"
syntaxhighlighting = "Source Code"
markdown = "Markdown"
[traffic]
limit = 10
header = "X_FORWARDED_FOR"
dir = PATH "data"
[purge]
limit = 300
batchsize = 10
dir = PATH "data"
[model]
class = Filesystem
[model_options]
dir = PATH "data"
```
Then the nginx vhost file, fairly straightforward too:
``` nginx
###############################################################################
# \_o< WARNING : This file is being managed by ansible! >o_/ #
# ~~~~ ~~~~ #
###############################################################################
server {
listen 80;
listen [::]:80;
server_name paste.adyxax.org;
location / {
return 308 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name paste.adyxax.org;
location / {
proxy_pass http://127.0.0.1:8082;
}
ssl_certificate adyxax.org.fullchain;
ssl_certificate_key adyxax.org.key;
}
```
## Migration process
The first step is to deploy this new configuration to the server:
``` shell
make run limit=lore.adyxax.org tags=paste.adyxax.org
```
After that I log in and manually migrate the privatebin data folder. On the old server I make a backup with:
``` shell
systemctl stop podman-privatebin
tar czf /tmp/privatebin.tar.gz /srv/privatebin/
```
I retrieve this backup on my laptop and send it to the new server with:
``` shell
scp root@myth.adyxax.org:/tmp/privatebin.tar.gz .
scp privatebin.tar.gz root@lore.adyxax.org:
```
On the new server, I restore the backup with:
``` shell
systemctl stop podman-privatebin
tar -xzf privatebin.tar.gz -C /srv/privatebin/
chown -R 65534:65534 /srv/privatebin
chmod -R u=rwX /srv/privatebin
systemctl start podman-privatebin
```
I then test the new server by setting the record in my `/etc/hosts` file. Since all works well, I rollback my change to `/etc/hosts` and update the DNS record using OpenTofu. I then clean up by running this on my laptop:
``` shell
rm privatebin.tar.gz
ssh root@myth.adyxax.org 'rm /tmp/privatebin.tar.gz'
ssh root@lore.adyxax.org 'rm privatebin.tar.gz'
```
## Conclusion
I did all this in early October, my backlog of blog articles is only growing!
|