From b3794ea1d51e4904f04bc3e37e819e7453287246 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Fri, 16 Dec 2022 16:51:59 +0000 Subject: [PATCH] Use magic domain guessing in Mailman 3 Setting SITE_ID=0 in settings.py is a signal to Postorius and Hyperkitty that they should guess the domain and filter lists based on the hostname supplied by the browser: https://docs.mailman3.org/en/latest/faq.html#the-domain-name-displayed-in-hyperkitty-shows-example-com-or-something-else Change-Id: I34df58fd95df3ff8075850ac370be9260a245021 --- .../roles/mailman3/files/web-settings.py | 5 +- playbooks/roles/mailman3/tasks/main.yaml | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/playbooks/roles/mailman3/files/web-settings.py b/playbooks/roles/mailman3/files/web-settings.py index 8e2905e2d4..23f47c1226 100644 --- a/playbooks/roles/mailman3/files/web-settings.py +++ b/playbooks/roles/mailman3/files/web-settings.py @@ -1,6 +1,6 @@ # This file has been copied from: # https://github.com/maxking/docker-mailman/blob/2693386453ff3865b7c106c6aa456b683bd3bf08/web/mailman-web/settings.py -# In order to override the ALLOWED_HOSTS setting. +# In order to override the ALLOWED_HOSTS and SITE_ID settings. # # -*- coding: utf-8 -*- # Copyright (C) 1998-2016 by the Free Software Foundation, Inc. @@ -47,7 +47,8 @@ ADMINS = ( ('Mailman Suite Admin', 'root@localhost'), ) -SITE_ID = 1 +# Magic value to perform automatic domain guessing +SITE_ID = 0 # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/3.1/ref/settings/#allowed-hosts diff --git a/playbooks/roles/mailman3/tasks/main.yaml b/playbooks/roles/mailman3/tasks/main.yaml index ca8c579faa..2ec20efadc 100644 --- a/playbooks/roles/mailman3/tasks/main.yaml +++ b/playbooks/roles/mailman3/tasks/main.yaml @@ -77,6 +77,21 @@ group: 101 mode: '0644' +- name: Check for initial setup flag file + stat: + path: /var/lib/mailman/bootstrapped + register: _mailman_bootstrapped + +# https://docs.mailman3.org/en/latest/faq.html#the-domain-name-displayed-in-hyperkitty-shows-example-com-or-something-else +- name: Temporarily turn off magic domain guessing + lineinfile: + state: present + backrefs: yes + path: /var/lib/mailman/web/settings.py + regexp: '^SITE_ID = 0$' + line: 'SITE_ID = 1' + when: not _mailman_bootstrapped.stat.exists + - name: Copy our settings_local.py for mailman-web copy: src: web-settings_local.py @@ -228,6 +243,49 @@ --email '{{ mailman3_admin_email }}'" no_log: true +- name: Complete new server bootstrapping + when: not _mailman_bootstrapped.stat.exists + block: + - name: Run docker-compose down + shell: + cmd: docker-compose down + chdir: /etc/mailman-compose/ + + - name: Turn magic domain guessing back on + lineinfile: + state: present + backrefs: yes + path: /var/lib/mailman/web/settings.py + regexp: '^SITE_ID = 0$' + line: 'SITE_ID = 1' + + - name: Create the bootstrapped flag file + copy: + content: "" + dest: /var/lib/mailman/bootstrapped + force: no + owner: 100 + group: 101 + mode: '0644' + + - name: Run docker-compose up + shell: + cmd: docker-compose up -d + chdir: /etc/mailman-compose/ + + - name: Wait for mm3 REST API to be up and running + uri: + url: 'http://localhost:8001/3.1/domains' + url_username: restadmin + url_password: "{{ mailman3_rest_password }}" + force_basic_auth: yes + method: GET + register: mm_rest_api_up + delay: 1 + retries: 300 + until: mm_rest_api_up and mm_rest_api_up.status == 200 + no_log: true + - name: Create lists in mm3 include_tasks: create_lists.yaml loop: "{{ mailman_sites }}"