03_provision_domain.ymlยถ

---
# The domain was asserted provisionable in 00_core.yml before any state change.
- name: "๐Ÿ“– List existing Stalwart domains"
  include_tasks: jmap_call.yml
  vars:
    stalwart_jmap_body: >-
      {{ {'using': ['urn:ietf:params:jmap:core', 'urn:stalwart:jmap'],
          'methodCalls': [['x:Domain/get', {'ids': none}, 'c0']]} | to_json }}

- name: "๐Ÿ” Resolve existing domain id (if any)"
  ansible.builtin.set_fact:
    stalwart_domain_id: >-
      {{ (stalwart_jmap.methodResponses[0][1].list
          | selectattr('name', 'equalto', STALWART_DOMAIN)
          | map(attribute='id') | first) | default('') }}

- name: "๐Ÿ“ Create the Stalwart domain when it does not exist yet"
  when: stalwart_domain_id | length == 0
  block:
    - name: "๐Ÿ“ Create Stalwart domain '{{ STALWART_DOMAIN }}'"
      include_tasks: jmap_call.yml
      vars:
        stalwart_jmap_body: >-
          {{ {'using': ['urn:ietf:params:jmap:core', 'urn:stalwart:jmap'],
              'methodCalls': [['x:Domain/set',
                {'create': {'d': {'name': STALWART_DOMAIN}}}, 'c0']]} | to_json }}

    - name: "๐Ÿ“– Capture newly created domain id"
      ansible.builtin.set_fact:
        stalwart_domain_id: "{{ stalwart_jmap.methodResponses[0][1].created.d.id }}"

- name: "โš™๏ธ Provision Stalwart accounts"
  include_tasks: 04_manage_user.yml
  when: STALWART_USERS | length > 0

- name: "๐Ÿ”ง Configure Stalwart mail-listener TLS (platform cert)"
  include_tasks: 05_tls.yml
  when: (lookup('tls', application_id, 'enabled') | bool) or (STALWART_ACTIVE_PROVIDER | bool)

- name: "๐Ÿ”— Wire Keycloak as the OIDC authentication directory (SSO)"
  include_tasks: 06_oidc.yml
  when: STALWART_SSO_ENABLED | bool

- name: "๐Ÿ”ง Register the ClamAV antivirus milter"
  include_tasks: 07_antivirus.yml
  when: STALWART_ANTIVIRUS_ENABLED | bool

- name: "๐Ÿ“– Read Stalwart-managed DKIM public key"
  include_tasks: 08_read_dkim.yml

- name: "๐Ÿ”ง Publish Stalwart DNS records"
  include_tasks: 09_dns-records.yml
  when: stalwart_dkim_selector is defined

- name: "๐Ÿ”Ž Verify the production mail server's public configuration"
  include_tasks: 13_production_facts.yml
  when: STALWART_PRODUCTION_HOST | length > 0

- name: "๐Ÿง… Route .onion recipients through the Tor SMTP gateway"
  include_tasks: 14_onion_route.yml
  when: STALWART_ONION_ACTIVE | bool

- name: "๐Ÿ“ฎ Provision the declared mail aliases and catch-alls"
  include_tasks: 15_aliases.yml

- name: "๐Ÿ”€ Deliver the mail of the alias domains to their target domains"
  include_tasks: 17_alias_domains.yml
  when: STALWART_ALIAS_DOMAINS | length > 0