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


- name: install opendmarc
  apt:
    pkg:
    - opendmarc
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


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


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


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


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