---
- name: install OpenDKIM
  apt:
    name:
      - opendkim
      - opendkim-tools
      - ssl-cert
      - dns-root-data
    state: present
  tags:
  - opendkim

- name: Add user opendkim in ssl-cert group
  user:
    name: opendkim
    groups: ssl-cert
    state: present
    append: yes
  tags:
  - opendkim

- name: add 127.0.0.1 to TrustedHosts
  lineinfile:
    dest: '/etc/opendkim/TrustedHosts'
    line: '127.0.0.1'
    create: True
    owner: opendkim
    group: opendkim
    mode: "0640"
  notify: reload opendkim
  tags:
  - opendkim

- name: create config files
  file:
    name: "/etc/opendkim/{{ item }}"
    state: touch
    owner: opendkim
    group: opendkim
    mode: "0640"
  loop:
  - 'KeyTable'
  - 'SigningTable'
  changed_when: False
  tags:
  - opendkim

- name: copy OpenDKIM config
  copy:
    src: opendkim.conf
    dest: /etc/opendkim.conf
    mode: "0644"
    force: yes
  notify: restart opendkim
  tags:
  - opendkim


- name: Set folder permissions to 0750
  file:
    path: "/etc/opendkim/"
    owner: opendkim
    group: opendkim
    mode: "0750"
    force: yes
  tags:
  - opendkim

- name: ensure opendkim is started and enabled
  systemd:
    name: opendkim
    state: started
    enabled: True
  tags:
  - opendkim

- include_role:
    name: evolix/remount-usr

- name: deploy opendkim-add.sh script
  copy:
    src: opendkim-add.sh
    dest: /usr/share/scripts/opendkim-add.sh
    mode: "0750"
  tags:
  - opendkim
