From: Oleg Broytman Date: Mon, 26 Aug 2019 15:09:08 +0000 (+0300) Subject: Feat(sa-merge-all): Merge SpamAssassin databases X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=f469669e463367cbdad0d4842ace6308c1bbe312;p=ansible.git Feat(sa-merge-all): Merge SpamAssassin databases --- diff --git a/playbooks/debian/sa-merge-all.yml b/playbooks/debian/sa-merge-all.yml new file mode 100644 index 0000000..7c35a93 --- /dev/null +++ b/playbooks/debian/sa-merge-all.yml @@ -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*"