]> git.phdru.name Git - ansible.git/commitdiff
Feat(sa-merge-all): Merge SpamAssassin databases
authorOleg Broytman <phd@phdru.name>
Mon, 26 Aug 2019 15:09:08 +0000 (18:09 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 26 Aug 2019 15:14:48 +0000 (18:14 +0300)
playbooks/debian/sa-merge-all.yml [new file with mode: 0644]

diff --git a/playbooks/debian/sa-merge-all.yml b/playbooks/debian/sa-merge-all.yml
new file mode 100644 (file)
index 0000000..7c35a93
--- /dev/null
@@ -0,0 +1,51 @@
+- name: Merge SpamAssassin databases
+  hosts: "{{ hosts | default('all') }}"
+  gather_facts: false
+  tasks:
+    - block:
+      - name: Stop exim
+        become: true
+        service:
+          name: exim4
+          state: stopped
+      - name: Stop SpamAssassin
+        become: true
+        service:
+          name: spamassassin
+          state: stopped
+
+      - name: Backup SpamAssassin DB
+        shell: "exec sa-learn --backup >~/tmp/sa-learn.backup@{{ inventory_hostname }}"
+      - name: Fetch SpamAssassin DB backup
+        synchronize:
+          src: "~/tmp/sa-learn.backup@{{ inventory_hostname }}"
+          dest: "~/tmp/sa-learn.backup@{{ inventory_hostname }}"
+          mode: pull
+      when: inventory_hostname != 'localhost'
+
+    - name: Combine SpamAssassin DB backups
+      shell: "cd ~/tmp && exec cat sa-learn.backup.* >sa-learn.backup"
+      when: inventory_hostname == 'localhost'
+
+    - block:
+      - name: Push combined SpamAssassin DB backup
+        synchronize:
+          src: "~/tmp/sa-learn.backup"
+          dest: "~/tmp/sa-learn.backup"
+      - name: Combine SpamAssassin DB backups
+        shell: "cd tmp && sa-learn --clear && sa-learn --restore sa-learn.backup && exec sa-learn --sync"
+
+      - name: Start SpamAssassin
+        become: true
+        service:
+          name: spamassassin
+          state: started
+      - name: Start exim
+        become: true
+        service:
+          name: exim4
+          state: started
+      when: inventory_hostname != 'localhost'
+
+    - name: Cleanup
+      shell: "cd ~/tmp && exec rm sa-learn.backup*"