---
- name: install rspamd
  pacman: name=rspamd state=present

- name: install config
  copy: src=local.d/ dest=/etc/rspamd/local.d/ owner=root group=root mode=0644
  notify:
    - reload rspamd

- name: install dkim_signing.conf
  template: src=dkim_signing.conf.j2 dest=/etc/rspamd/local.d/dkim_signing.conf owner=root group=root mode=0644
  notify:
    - reload rspamd

- name: create rspamd dkim directory
  file: path=/var/lib/rspamd/dkim state=directory owner=rspamd group=rspamd mode=0750

# For this to run, you need to generate the keys first
# run
#
# rspamadm dkim_keygen -s dkim-ed25519 -b 0 -d archlinux.org -t ed25519 -k archlinux.org.dkim-ed25519.key
# rspamadm dkim_keygen -s dkim-rsa -b 4096 -d archlinux.org -t rsa -k archlinux.org.dkim-rsa.key
#
# the ouput gives you the DNS entries to add to the terraform files.
# The keys generated need to go to the vault:
# roles/rspamd/files/archlinux.org.dkim-rsa.key
# roles/rspamd/files/archlinux.org.dkim-ed25519.key
#
- name: install DKIM keys
  copy: src={{ item }} dest=/var/lib/rspamd/dkim/ owner=rspamd group=rspamd mode=0600
  loop:
    - "{{ rspamd_dkim_domain }}.dkim-ed25519.key"
    - "{{ rspamd_dkim_domain }}.dkim-rsa.key"
  notify:
    - reload rspamd

- name: start and enable rspamd
  service: name=rspamd enabled=yes state=started
