run.ymlΒΆ

---
# include-gated: when: STALWART_IMPORT_MAILU and 'web-app-mailu' in group_names
#                and STALWART_ACTIVE_PROVIDER and IS_COMPOSE_MODE
# Param: stalwart_mailu_maildir - registered result whose stdout is the maildir volume mountpoint.
- name: "πŸ“ Create the import working directory"
  ansible.builtin.file:
    path: "{{ STALWART_IMPORT_DIR }}"
    state: directory
    mode: "0700"

- name: "πŸ“₯ Stage and start the Mailu import in the background"
  block:
    - name: "πŸ“„ Stage the import scripts"
      ansible.builtin.copy:
        src: "{{ [ 'python', stalwart_import_script ] | path_join }}"
        dest: "{{ [ STALWART_IMPORT_DIR, stalwart_import_script ] | path_join }}"
        mode: "0600"
      loop: "{{ STALWART_IMPORT_SCRIPTS }}"
      loop_control:
        loop_var: stalwart_import_script

    - name: "πŸ“„ Stage the recovery administrator credentials for the import"
      ansible.builtin.copy:
        content: "{{ {'user': STALWART_ADMIN_USER, 'password': STALWART_ADMIN_PASSWORD} | to_json }}"
        dest: "{{ STALWART_IMPORT_ADMIN_FILE }}"
        mode: "0600"
      no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"

    - name: "πŸ“₯ Start the import unit and confirm systemd runs it"
      include_tasks: "{{ role_path }}/tasks/12_import_mailu/start.yml"
  rescue:
    - name: "🧹 Remove the import working directory and its credentials" # nocheck: rescue-credentials the staged recovery administrator password would otherwise outlive a unit that never started, since only the unit's ExecStopPost removes it
      ansible.builtin.file:
        path: "{{ STALWART_IMPORT_DIR }}"
        state: absent

    - name: "πŸ›‘ Re-raise the failure that stopped the import start"
      ansible.builtin.fail:
        msg: "{{ ansible_failed_result.msg }}"

- name: "πŸ“‹ Report where the import logs its progress"
  ansible.builtin.debug:
    msg: "{{ (stalwart_import_start.stderr ~ ' ' ~ stalwart_import_start.stdout) | trim }}; follow it with: journalctl -fu {{ STALWART_IMPORT_UNIT }}"