1 #####################################
2 ### someone's ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2024 by someone <someone@somenet.org>
7 # system backup script + systemd timer
10 - name: install backup tool
18 ignore_errors: "{{ignore_online_errors | bool}}"
21 - name: create dir /bkp
30 - name: create dir /bkp/local
39 - name: create dir /bkp/storage-local
41 path: "/bkp/storage-local"
49 - name: copy backup.sh to /bkp/local
52 dest: "/bkp/local/backup.sh"
57 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/backup.sh"
58 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/backup.sh"
59 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/backup.sh"
63 - name: copy backup.conf.managed to /bkp/local
66 dest: "/bkp/local/backup.conf.managed"
71 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/backup.conf.managed"
72 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/backup.conf.managed"
73 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/backup.conf.managed"
74 - "default/backup.conf.managed"
77 - name: create dir /bkp/local/exclude.conf.d
79 path: "/bkp/local/exclude.conf.d"
86 - name: copy etc--00-global.managed to /bkp/local/exclude.conf.d
89 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--etc--00-global.managed"
94 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/etc--00-global.managed"
95 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/etc--00-global.managed"
96 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/etc--00-global.managed"
97 - "default/exclude/etc--00-global.managed"
100 - name: copy etc--10-host.managed to /bkp/local/exclude.conf.d
103 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--etc--10-host.managed"
108 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/etc--10-host.managed"
109 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/etc--10-host.managed"
110 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/etc--10-host.managed"
111 - "default/exclude/etc--10-host.managed"
114 - name: copy root--00-global.managed to /bkp/local/exclude.conf.d
117 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--root--00-global.managed"
122 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/root--00-global.managed"
123 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/root--00-global.managed"
124 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/root--00-global.managed"
125 - "default/exclude/root--00-global.managed"
128 - name: copy root--10-host.managed to /bkp/local/exclude.conf.d
131 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--root--10-host.managed"
136 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/root--10-host.managed"
137 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/root--10-host.managed"
138 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/root--10-host.managed"
139 - "default/exclude/root--10-host.managed"
142 - name: copy srv--00-global.managed to /bkp/local/exclude.conf.d
145 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--srv--00-global.managed"
150 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/srv--00-global.managed"
151 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/srv--00-global.managed"
152 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/srv--00-global.managed"
153 - "default/exclude/srv--00-global.managed"
156 - name: copy srv--10-host.managed to /bkp/local/exclude.conf.d
159 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--srv--10-host.managed"
164 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/srv--10-host.managed"
165 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/srv--10-host.managed"
166 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/srv--10-host.managed"
167 - "default/exclude/srv--10-host.managed"
170 - name: copy var--00-global.managed to /bkp/local/exclude.conf.d
173 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--var--00-global.managed"
178 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/var--00-global.managed"
179 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/var--00-global.managed"
180 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/var--00-global.managed"
181 - "default/exclude/var--00-global.managed"
184 - name: copy var--10-host.managed to /bkp/local/exclude.conf.d
187 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--var--10-host.managed"
192 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/var--10-host.managed"
193 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/var--10-host.managed"
194 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/var--10-host.managed"
195 - "default/exclude/var--10-host.managed"
198 - name: copy backup.service to /etc/systemd/system/
201 dest: "/etc/systemd/system/backup.service"
206 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/backup.service"
207 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/backup.service"
208 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/backup.service"
209 - "default/backup.service"
212 - name: copy home--00-global.managed to /bkp/local/exclude.conf.d
215 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--home--00-global.managed"
220 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/home--00-global.managed"
221 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/home--00-global.managed"
222 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/home--00-global.managed"
223 - "default/exclude/home--00-global.managed"
226 - name: copy home--10-host.managed to /bkp/local/exclude.conf.d
229 dest: "/bkp/local/exclude.conf.d/{{inventory_hostname}}--home--10-host.managed"
234 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/exclude/home--10-host.managed"
235 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/exclude/home--10-host.managed"
236 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/exclude/home--10-host.managed"
237 - "default/exclude/home--10-host.managed"
240 - name: copy backup.timer to /etc/systemd/system/
243 dest: "/etc/systemd/system/backup.timer"
248 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/backup.timer"
249 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/backup.timer"
250 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/backup.timer"
251 - "default/backup.timer"
254 - name: enable and start backup.timer
255 include_role: name="base/systemd/enable-and-start"
257 service_name: backup.timer
261 ###############################
262 # setup backup storage server #
263 ###############################
264 - name: create borg-storage user
267 home: "/bkp/storage-server"
272 when: setup_backup_storage_server | bool
275 - name: create dir /bkp/storage-server
277 path: "/bkp/storage-server"
280 owner: "borg-storage"
281 group: "borg-storage"
283 when: setup_backup_storage_server | bool
286 - name: create dir /bkp/storage-server/.ssh
288 path: "/bkp/storage-server/.ssh"
291 owner: "borg-storage"
292 group: "borg-storage"
293 when: setup_backup_storage_server | bool
296 - name: copy authorized_keys to /bkp/storage-server/.ssh/authorized_keys
299 dest: "/bkp/storage-server/.ssh/authorized_keys"
301 owner: "borg-storage"
302 group: "borg-storage"
304 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/backup-server.authorized_keys"
305 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/backup-server.authorized_keys"
306 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/backup-server.authorized_keys"
307 - "default/backup-server.authorized_keys"
308 when: setup_backup_storage_server | bool