summaryrefslogtreecommitdiffstats
path: root/roles/bacula-sd/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/bacula-sd/tasks')
-rw-r--r--roles/bacula-sd/tasks/main.yml110
1 files changed, 110 insertions, 0 deletions
diff --git a/roles/bacula-sd/tasks/main.yml b/roles/bacula-sd/tasks/main.yml
new file mode 100644
index 0000000..7a6c8c3
--- /dev/null
+++ b/roles/bacula-sd/tasks/main.yml
@@ -0,0 +1,110 @@
+- name: Install stunnel
+ apt: pkg=stunnel4
+
+- name: Auto-enable stunnel
+ lineinfile: dest=/etc/default/stunnel4
+ regexp='^(\s*#)?\s*ENABLED='
+ line='ENABLED=1'
+ owner=root group=root
+ mode=0644
+
+- 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
+ tags:
+ - genkey
+
+- name: Fetch Bacula SD X.509 certificate
+ # Ensure we don't fetch private data
+ sudo: 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
+
+- 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
+
+- name: Start stunnel
+ service: name=stunnel4 pattern=/usr/bin/stunnel4 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