---
- name: Mail Playbook (K8s)
  hosts: mail
  gather_facts: true

# Specific tasks for this playbook
  tasks:
    - name: Set required facts
      ansible.builtin.set_fact:
        mail_home: "{{ persistent_data | default('/var/lib') }}/mail"
        mail_user_id: 1000
        mail_group_id: 1000
        postfix_user_id: 100
        postfix_group_id: 101
      tags: always

    - name: Set required facts
      ansible.builtin.set_fact:
        mail_folders:
          - "{{ mail_home }}/getmail"
          - "{{ mail_home }}/mailboxes"
      tags: always

    - name: Create required mail home folder
      become: true
      ansible.builtin.file:
        state: directory
        path: "{{ mail_home }}"
        mode: "0750"
        owner: "{{ mail_user_id }}"
        group: "{{ mail_group_id }}"
      tags:
        - tasks
        - tasks::folders

    - name: Create required mail folders
      become: true
      ansible.builtin.file:
        state: directory
        path: "{{ item }}"
        mode: "0750"
        owner: "{{ mail_user_id }}"
        group: "{{ mail_group_id }}"
      loop: "{{ mail_folders }}"
      tags:
        - tasks
        - tasks::folders

    - name: Create required postfix folders
      become: true
      ansible.builtin.file:
        state: directory
        path: "{{ item }}"
        mode: "0750"
        owner: "{{ postfix_user_id }}"
        group: "{{ postfix_group_id }}"
      loop:
        - "{{ mail_home }}/postfix"
      tags:
        - tasks
        - tasks::folders
