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
|
---
- hosts: all
any_errors_fatal: true
gather_facts: no
pre_tasks:
- name: Install Python 2 for Ansible fact gathering
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
- hosts: all
any_errors_fatal: true
tasks:
- name: Update Ubuntu server
apt:
update_cache: yes
upgrade: dist
- name: Install apt packages
apt:
name: [ 'docker-compose', 'borgbackup' ]
state: latest
- name: Create /home/vps/ base directory
file:
path: /home/vps/
state: directory
- name: Create symlink to attached volume
file:
src: /mnt/${VPS_VOLUME_NAME}
dest: /home/vps/volumes
state: link
- name: Copy local interpolated files to remote
copy: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }}
with_items:
- { src: './restore-backup.sh', dest: '/home/vps/restore-backup.sh', mode: '500' }
- { src: '../secrets/borg/borg-remote.pub', dest: '/root/.ssh/id_rsa.pub', mode: '400' }
- { src: '../secrets/borg/borg-remote', dest: '/root/.ssh/id_rsa', mode: '400' }
- { src: '../secrets/borg/known-hosts.txt', dest: '/root/.ssh/known_hosts', mode: '400' }
- { src: '../scripts/box/bash-profile.sh', dest: '/root/.bash_profile', mode: '400' }
- { src: './docker-compose.yaml', dest: '/home/vps/docker-compose.yaml', mode: '400' }
- name: Restore borg backup when we have a fresh volume
shell: /home/vps/restore-backup.sh
when: lookup('env', 'DESTROY_VOLUME') == "1"
- name: Create the required Docker network
docker_network:
name: nginx-proxy
- name: Start docker-compose
docker_compose:
project_src: /home/vps/
pull: yes
state: present
|