summaryrefslogtreecommitdiffstats
path: root/roles/bacula-sd/tasks/main.yml
blob: 5de0d3d28091e2348ddd42a4f65d0d51d668b75a (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
- name: Create /etc/stunnel/certs
  file: path=/etc/stunnel/certs
        state=directory
        owner=root group=root
        mode=0755

- name: Generate a private key and a X.509 certificate for Bacula SD
  command: genkeypair.sh x509
                         --pubkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.pem
                         --privkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.key
                         --ou=BaculaSD --cn={{ inventory_hostname }} --dns={{ inventory_hostname }}
                         -t rsa -b 4096 -h sha512
  register: r1
  changed_when: r1.rc == 0
  failed_when: r1.rc > 1
  notify:
    - Restart stunnel@bacula-sd
  tags:
    - genkey

- name: Fetch Bacula SD X.509 certificate
  # Ensure we don't fetch private data
  become: False
  fetch: src=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.pem
         dest=certs/bacula/
         fail_on_missing=yes
         flat=yes
  tags:
    - genkey

- name: Copy Bacula Dir/FD X.509 certificates
  assemble: src=certs/bacula regexp="-(dir|fd)\.pem$" remote_src=no
            dest=/etc/stunnel/certs/bacula-dir+fds.pem
            owner=root group=root
            mode=0644
  register: r2
  notify:
    - Restart stunnel@bacula-sd

- name: Configure stunnel
  template: src=etc/stunnel/bacula-sd.conf.j2
            dest=/etc/stunnel/bacula-sd.conf
            owner=root group=root
            mode=0644
  register: r3
  notify:
    - Restart stunnel@bacula-sd

- name: Enable stunnel@bacula-sd
  service: name=stunnel4@bacula-sd enabled=yes

- name: Start stunnel
  service: name=stunnel4@bacula-sd state=started
  when: not (r1.changed or r2.changed or r3.changed)

- meta: flush_handlers



- name: Install bacula-sd
  apt: pkg=bacula-sd

# Create with:
#   echo $director-dir $(pwgen -sn 64 1) | sudo tee -a /etc/bacula/passwords-sd
- name: Ensure /etc/bacula/passwords-sd exists
  file: path=/etc/bacula/passwords-sd
        state=file
        owner=bacula group=bacula
        mode=0600

- name: Configure bacula
  template: src=etc/bacula/bacula-sd.conf.j2
            dest=/etc/bacula/bacula-sd.conf
            owner=root group=root
            mode=0644
  notify:
    - Restart bacula-sd

- name: Copy bacula-sd.service
  copy: src=lib/systemd/system/bacula-sd.service
        dest=/lib/systemd/system/bacula-sd.service
        owner=root group=root
        mode=0644
  notify:
    - systemctl daemon-reload
    - Restart bacula-sd

- meta: flush_handlers

- name: Enable bacula-sd
  service: name=bacula-sd enabled=yes

- name: Start bacula-sd
  service: name=bacula-sd state=started

# To avoid bacula creating archives under /mnt/backup/bacula when it's
# not a mountpoint, use `chmod 0700 /mnt/backup; chown root:root /mnt/backup`
# before mounting the disk.
- name: Create /mnt/backup/bacula
  file: path=/mnt/backup/bacula
        state=directory
        owner=bacula group=tape
        mode=0750