#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install spamassassin
  apt:
    pkg:
    - sa-compile
    - spamassassin
    - spamc
    - spamd
    state: present
    policy_rc_d: 101
  tags: "online"


- name: copy spamd defaults
  copy:
    src: "{{item}}"
    dest: "/etc/default/spamd"
    owner: "root"
    group: "root"
    mode: 0644
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/spamd.defaults"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/spamd.defaults"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/spamd.defaults"
    - "default/spamd.defaults"
  notify: restart spamd.service


- name: copy spamassassin config
  copy:
    src: "{{item}}"
    dest: "/etc/spamassassin/local.cf"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/local.cf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/local.cf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/local.cf"
    - "default/local.cf"
  notify: restart spamd.service


- name: copy spamassassin-expire cronjob
  copy:
    src: "{{item}}"
    dest: "/etc/cron.d/spamassassin-expire"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/spamassassin-expire.cron"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/spamassassin-expire.cron"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/spamassassin-expire.cron"
    - "default/spamassassin-expire.cron"


- name: enable and start spamd.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: spamd.service
