#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install opendkim
  apt:
    pkg:
    - opendkim
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: remove opendkim.conf
  file:
    path: "/etc/opendkim.conf"
    state: absent


- name: create opendkim config dir
  file:
    path: "/etc/opendkim"
    state: directory
    mode: 0700
    owner: "opendkim"
    group: "opendkim"


- name: copy opendkim configs and keys
  copy:
    src:  "{{item.src}}"
    dest: "/etc/opendkim/{{item.path}}"
    mode: 0600
    owner: "opendkim"
    group: "opendkim"
  with_filetree:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/opendkim/"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/opendkim/"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/opendkim/"
    - "default/opendkim/"
  when: item.state == "file"
  notify: restart opendkim.service


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


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