--- /dev/null
+- 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*"