12_import_mailu.ymlΒΆ

---
# include-gated: when: STALWART_IMPORT_MAILU and 'web-app-mailu' in group_names
#                and STALWART_ACTIVE_PROVIDER and IS_COMPOSE_MODE
- name: "πŸ” List the container volumes on the stack host"
  ansible.builtin.command: >-
    container volume ls --format "{{ '{{' }} .Name {{ '}}' }}"
  register: stalwart_volume_names
  changed_when: false

- name: "ℹ️ Report that Mailu has no maildir volume to import yet"
  ansible.builtin.debug:
    msg: "Mailu's maildir volume {{ STALWART_MAILU_MAILDIR_VOLUME }} does not exist on this host yet; there is nothing to import."
  when: STALWART_MAILU_MAILDIR_VOLUME not in stalwart_volume_names.stdout_lines

- name: "πŸ“¨ Handle the Mailu maildir volume this host carries"
  when: STALWART_MAILU_MAILDIR_VOLUME in stalwart_volume_names.stdout_lines
  block:
    - name: "πŸ” Check whether a finished import left its marker"
      ansible.builtin.stat:
        path: "{{ STALWART_IMPORT_DONE_FILE }}"
      register: stalwart_import_done

    - name: "ℹ️ Report that the Mailu import is complete"
      ansible.builtin.debug:
        msg: "The Mailu import finished earlier; delete {{ STALWART_IMPORT_DONE_FILE }} to import again."
      when: stalwart_import_done.stat.exists

    - name: "πŸ“₯ Import the Mailu mailboxes unless an earlier run finished"
      when: not stalwart_import_done.stat.exists
      block:
        - name: "πŸ” Read the state of the import unit"
          ansible.builtin.command:
            argv:
              - systemctl
              - show
              - --property
              - ActiveState
              - --value
              - "{{ STALWART_IMPORT_UNIT }}"
          register: stalwart_import_unit_state
          changed_when: false

        - name: "ℹ️ Report that the import of an earlier deploy still runs"
          ansible.builtin.debug:
            msg: "{{ STALWART_IMPORT_UNIT }} is {{ stalwart_import_unit_state.stdout }}; follow it with: journalctl -fu {{ STALWART_IMPORT_UNIT }}"
          when: stalwart_import_unit_state.stdout not in ['inactive', 'failed']

        - name: "πŸ“₯ Import every Mailu mailbox into Stalwart"
          when: stalwart_import_unit_state.stdout in ['inactive', 'failed']
          block:
            - name: "πŸ” Resolve the legacy Mailu maildir volume mountpoint"
              ansible.builtin.command: >-
                container volume inspect --format "{{ '{{' }} .Mountpoint {{ '}}' }}"
                {{ STALWART_MAILU_MAILDIR_VOLUME | quote }}
              register: stalwart_mailu_maildir
              changed_when: false

            - name: "πŸ“₯ Stage and start the import"
              include_tasks: 12_import_mailu/run.yml