summaryrefslogtreecommitdiffstats
path: root/roles/IMAP/tasks/spam.yml
blob: c275b551963400abad3377bb5cac7ae6409300b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
- name: Install spamassassin
  apt: pkg={{ packages }}
  vars:
    packages:
    # The following two lines are for the policy lookup (made by amavis)
    - libnet-ldap-perl
    - libauthen-sasl-perl
    - razor
    - spamassassin
    - spamc
    - libdbi-perl
    - re2c
    - libc6-dev
    - gcc
    - make
  notify:
    - Compile Spamassassin rules
    - Restart Amavis

- name: Create a 'spamassassin' database
  mysql_db: name=spamassassin state=present
            encoding=latin1 collation=latin1_general_ci
  notify:
    - Copy SQL tables for spamassassin
    - Create SQL tables for spamassassin

- meta: flush_handlers


- name: Copy SpamAssassin's configuration
  copy: src=etc/{{ item }}
        dest=/etc/{{ item }}
        owner=root group=root
        mode=0644
  with_items:
    - spamassassin/v310.pre
    - spamassassin/v320.pre
  register: r1
  notify:
    - Restart Amavis

- name: Copy SpamAssassin's configuration (2)
  template: src=etc/{{ item }}.j2
            dest=/etc/{{ item }}
            owner=root group=root
            mode=0644
  with_items:
    - spamassassin/local.cf
  register: r2
  notify:
    - Restart Amavis

- name: Provision /etc/default/spamassassin
  lineinfile: dest=/etc/default/spamassassin
              regexp='^(\\s*#)?\\s*{{ item.var }}\\s*='
              line='{{ item.var }}={{ item.value }}'
              owner=root group=root
              mode=0644
  with_items:
    - { var: ENABLED, value: 0 }
    - { var: CRON,    value: 1 }

- name: Create a 'amavis' SQL user
  # This *must* be the user we run spamd as
  # See https://svn.apache.org/repos/asf/spamassassin/trunk/sql/README.bayes
  mysql_user2: >
      name=amavis password= auth_plugin=auth_socket
      priv="spamassassin.awl:               SELECT,INSERT,UPDATE,DELETE
           /spamassassin.bayes_seen:        SELECT,INSERT,       DELETE
           /spamassassin.bayes_token:       SELECT,INSERT,UPDATE,DELETE
           /spamassassin.bayes_global_vars: SELECT
           /spamassassin.bayes_vars:        SELECT,INSERT,UPDATE,DELETE
           /spamassassin.bayes_expire:      SELECT,INSERT,       DELETE"
      state=present
  register: r3
  notify:
    - Restart Amavis

- name: Start Amavis
  service: name=amavis state=started
  when: not (r1.changed or r2.changed or r3.changed)

- meta: flush_handlers