# vim: ft=yaml.ansible
---
- name: Create subfolders
  file:
    name: "{{ services.mailu.volume_folder }}/{{ volume }}"
    state: directory
  loop:
    - redis
    - certs
    - data
    - dkim
    - mail
    - mailqueue
    - filter
    - postgres
    - webmail
    - overrides
    - overrides/nginx
    - overrides/dovecot
    - overrides/postfix
    - overrides/rspamd
    - overrides/snappymail
  loop_control:
    loop_var: volume

- name: Upload mailu.env file
  template:
    src: mailu/env.j2
    dest: "{{ services.mailu.volume_folder }}/mailu.env"

- name: Hard link to Let's Encrypt TLS certificate
  file:
    src: "{{ services.nginx_proxy.volume_folder }}/certs/{{ services.mailu.domain }}/fullchain.pem"
    dest: "{{ services.mailu.volume_folder }}/certs/cert.pem"
    state: hard
    force: true
  when: letsencrypt_enabled

- name: Hard link to Let's Encrypt TLS key
  file:
    src: "{{ services.nginx_proxy.volume_folder }}/certs/{{ services.mailu.domain }}/key.pem"
    dest: "{{ services.mailu.volume_folder }}/certs/key.pem"
    state: hard
    force: true
  when: letsencrypt_enabled