From f469669e463367cbdad0d4842ace6308c1bbe312 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 26 Aug 2019 18:09:08 +0300 Subject: [PATCH] Feat(sa-merge-all): Merge SpamAssassin databases --- playbooks/debian/sa-merge-all.yml | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 playbooks/debian/sa-merge-all.yml 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*" -- 2.39.5