summaryrefslogtreecommitdiffstats
path: root/roles/borgbackup/tasks/main.yml
blob: 085b99fcdac9607070dd2890325424933a2384ad (plain) (blame)
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
---

- name: Ensure borgbackup is installed
  package:
    name: borgbackup
    state: present

- name: Add borg group
  group:
    name: "{{ borg_group }}"
    state: present

- name: Add borg user
  user:
    name: "{{ borg_user }}"
    group: "{{ borg_group }}"
    home: "{{ borg_dir }}"
    shell: "{{ borg_shell }}"
    groups: []
    state: present

- name: Ensure borg user's home directory is present
  file:
    path: "{{ borg_dir }}"
    owner: "{{ borg_user }}"
    group: "{{ borg_group }}"
    mode: 0700
    state: directory

- name: Ensure .ssh directory exists
  file:
    path: "{{ borg_dir }}/.ssh"
    owner: "{{ borg_user }}"
    group: "{{ borg_group }}"
    mode: 0700
    state: directory

- name: Ensure pool exists
  file:
    path: "{{ borg_pool }}"
    owner: "{{ borg_user }}"
    group: "{{ borg_group }}"
    mode: 0700
    state: directory

# Be aware this does not remove other keys as authorized_key is broken when used
# in exclusive mode with with_items
- name: Setup authorized_keys
  authorized_key:
    user: "{{ borg_user }}"
    key: "{{ item.key }}"
    key_options: 'command="cd {{ borg_pool }}/{{ item.host }};borg serve --restrict-to-path {{ borg_pool }}/{{ item.host }}",restrict'
  with_items: "{{ borg_auth_users }}"

- name: Ensure .ssh/authorized_keys exists
  file:
    path: "{{ borg_dir }}/.ssh/authorized_keys"
    owner: "{{ borg_user }}"
    group: "{{ borg_group }}"
    mode: 0600
    state: file

- name: Ensure all the user pools exist
  file:
    path: "{{ borg_pool }}/{{ item.host }}"
    owner: "{{ borg_user }}"
    group: "{{ borg_group }}"
    mode: 0700
    state: directory
  with_items: "{{ borg_auth_users }}"