Skip to content

Commit e7eb980

Browse files
committed
Fix linting, add nginx, various other updates
1 parent aca5821 commit e7eb980

File tree

12 files changed

+170
-24
lines changed

12 files changed

+170
-24
lines changed

.github/workflows/lint-local.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: ansible-lint-local
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
- develop
10+
- feature/**
11+
jobs:
12+
ansible-lint-local:
13+
name: ansible-lint-local
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out the codebase.
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python 3.
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install test dependencies.
25+
run: pip3 install yamllint ansible-lint ansible
26+
27+
- name: Lint code.
28+
run: |
29+
set -e
30+
yamllint .
31+
ansible-lint .

.github/workflows/lint.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
---
12
name: ansible-lint
23
on: [pull_request_target]
34
jobs:
45
ansible-lint:
56
name: ansible-lint
67
runs-on: ubuntu-latest
78
steps:
8-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
910

10-
- uses: actions/setup-python@v2
11+
- uses: actions/setup-python@v3
1112
with:
1213
python-version: '3.x'
1314

.yamllint

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
extends: default
3+
rules:
4+
line-length:
5+
max: 400
6+
level: warning
7+
truthy:
8+
allowed-values:
9+
- 'true'
10+
- 'false'
11+
check-keys: true
12+
ignore: |
13+
.github/workflows

defaults/main.yml

+7
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,10 @@ __mailman3_os: >-
426426
ansible_os_family
427427
) | lower
428428
}}
429+
430+
# Server name nginx should listen on, defaults to inventory_hostname.
431+
mailman3_web_url: "{{ inventory_hostname }}"
432+
mailman3_install_nginx: true
433+
# Override this will a value similar to mailman3_web_url. Used in /etc/mailman3/hyperkitty.cfg:
434+
mailman3_hyperkitty_server_url: "http://localhost"
435+
mailman3_nginx_ssl_certs: "include snippets/snakeoil.conf;"

files/distribute_maps.playbook.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
- name: Distribute Mailman transport maps to backup MX servers
44
hosts: all
55
tasks:
6-
- name: Check postfix_lmtp
7-
stat:
6+
- name: Check postfix_lmtp # noqa run-once
7+
ansible.builtin.stat:
88
path: "{{ mailman3_core_var_dir }}/data/postfix_lmtp"
99
register: result
1010
delegate_to: localhost
1111
run_once: true
1212
- name: Copy postfix_lmtp
13-
copy:
13+
ansible.builtin.copy:
1414
src: "{{ mailman3_core_var_dir }}/data/postfix_lmtp"
1515
dest: "{{ mailman3_distribute_maps_dir }}/postfix_lmtp"
16+
mode: '0644'
1617
when: result.stat.exists
1718
notify:
18-
- postmap
19+
- Postmap
1920
handlers:
20-
- name: postmap
21-
command: "{{ mailman3_postmap_command | default('postmap') }} {{ mailman3_distribute_maps_dir | quote }}/postfix_lmtp"
21+
- name: Postmap
22+
changed_when: false
23+
ansible.builtin.command: "{{ mailman3_postmap_command | default('postmap') }} {{ mailman3_distribute_maps_dir | quote }}/postfix_lmtp"

handlers/main.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@
66

77
# invoke systemctl directly until someone implements https://github.com/ansible/ansible/issues/61763
88

9-
- name: Restart mailman3-core service
9+
- name: Restart mailman3-core service # noqa command-instead-of-module
1010
ansible.builtin.command: systemctl try-restart {{ mailman3_core_service_name }}.service
11-
args:
12-
# can't noqa a multi-line yaml string and noqa command-instead-of-module makes the line fail the line length rule
13-
warn: false
11+
changed_when: false
1412
when:
1513
- mailman3_process_manager == "systemd"
1614
- ansible_virtualization_type != "docker"
1715

18-
- name: Restart mailman3-web service
16+
- name: Restart mailman3-web service # noqa command-instead-of-module
1917
ansible.builtin.command: systemctl try-restart {{ mailman3_web_service_name }}{{ '@' if mailman3_domains is defined else '' }}{{ item }}.service
20-
args:
21-
warn: false
2218
loop: "{{ mailman3_domains | default(['']) }}"
19+
changed_when: false
2320
when:
2421
- mailman3_process_manager == "systemd"
2522
- ansible_virtualization_type != "docker"
2623

27-
- name: Reload mailman3-web service
24+
- name: Reload mailman3-web service # noqa command-instead-of-module
2825
ansible.builtin.command: systemctl try-reload-or-restart {{ mailman3_web_service_name }}{{ '@' if mailman3_domains is defined else '' }}{{ item }}.service
29-
args:
30-
warn: false
3126
loop: "{{ mailman3_domains | default(['']) }}"
27+
changed_when: false
3228
when:
3329
- mailman3_process_manager == "systemd"
3430
- ansible_virtualization_type != "docker"
31+
32+
- name: Restart nginx
33+
ansible.builtin.service:
34+
name: nginx
35+
state: restarted

tasks/config.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ansible.builtin.copy:
1515
content: |
1616
[general]
17-
base_url: http://localhost/{{ mailman3_hyperkitty_root | default('hyperkitty/') }}
17+
base_url: {{ mailman3_hyperkitty_server_url }}/{{ mailman3_hyperkitty_root | default('archives/') }}
1818
api_key: {{ mailman3_archiver_key }}
1919
dest: "{{ mailman3_core_etc_dir }}/hyperkitty.cfg"
2020
group: "{{ __mailman3_core_group_name }}"
@@ -42,3 +42,17 @@
4242
when: mailman3_wsgi_socket.startswith("/")
4343
notify:
4444
- Reload mailman3-web service
45+
46+
- name: Install digest cron task
47+
ansible.builtin.cron:
48+
name: "mailman digests"
49+
special_time: daily
50+
job: "{{ mailman3_install_dir}}/bin/mailman digests --periodic"
51+
user: "{{ __mailman3_core_user_name }}"
52+
53+
- name: Install notify cron task
54+
ansible.builtin.cron:
55+
name: "mailman notify"
56+
special_time: daily
57+
job: "{{ mailman3_install_dir}}/bin/mailman notify"
58+
user: "{{ __mailman3_core_user_name }}"

tasks/django.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
become_user: "{{ __mailman3_web_user_name }}"
4242

4343
- name: Create Django superusers
44-
community.general.django_manage: # noqa no-handler
44+
community.general.django_manage: # noqa no-handler
4545
command: >-
4646
shell -c 'import sys;
4747
from django.contrib.auth.models import User;
@@ -75,7 +75,7 @@
7575
become_user: "{{ __mailman3_web_user_name }}"
7676

7777
- name: Correct default Django site
78-
community.general.django_manage: # noqa no-handler
78+
community.general.django_manage: # noqa no-handler
7979
command: >-
8080
shell -c 'from django.contrib.sites.models import Site;
8181
Site.objects.filter(domain="example.com").update(

tasks/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
- name: Include Django management tasks
3131
ansible.builtin.import_tasks: django.yml
3232

33+
- name: Include Nginx tasks
34+
ansible.builtin.import_tasks: nginx.yml
35+
when: mailman3_install_nginx
36+
3337
- name: Include Postfix map distribution tasks
3438
ansible.builtin.include_tasks: distribute_maps.yml
3539
when: mailman3_distribute_maps is defined

tasks/nginx.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
3+
- name: Install Nginx packages
4+
ansible.builtin.package:
5+
name: "nginx"
6+
state: present
7+
8+
- name: Create letsencrypt renewal dir
9+
ansible.builtin.file:
10+
dest: "/var/www/letsencrypt"
11+
state: directory
12+
mode: '0755'
13+
14+
- name: Copy nginx vhost
15+
ansible.builtin.template:
16+
src: templates/vhost.j2
17+
dest: /etc/nginx/sites-available/mailman-web
18+
mode: '0644'
19+
notify: Restart nginx
20+
21+
- name: Create link to the new config to enable it
22+
ansible.builtin.file:
23+
dest: /etc/nginx/sites-enabled/mailman-web
24+
src: /etc/nginx/sites-available/mailman-web
25+
state: link
26+
notify: Restart nginx
27+
28+
- name: Remove default nginx vhost
29+
ansible.builtin.file:
30+
dest: /etc/nginx/sites-enabled/default
31+
state: absent
32+
notify: Restart nginx

templates/urls.py.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ from django.urls import path, reverse_lazy
2323
from django.views.generic import RedirectView
2424

2525
urlpatterns = [
26-
{% if mailman3_postorius_root | default('postorius/') %}
26+
{% if mailman3_postorius_root | default('mailman3/') %}
2727
path(
2828
'',
2929
RedirectView.as_view(url=reverse_lazy('list_index'), permanent=True),
3030
),
3131
{% endif %}
32-
path(r'{{ mailman3_postorius_root | default("postorius/") }}', include('postorius.urls')),
33-
path(r'{{ mailman3_hyperkitty_root | default("hyperkitty/") }}', include('hyperkitty.urls')),
32+
path(r'{{ mailman3_postorius_root | default("mailman3/") }}', include('postorius.urls')),
33+
path(r'{{ mailman3_hyperkitty_root | default("archives/") }}', include('hyperkitty.urls')),
3434
path('', include('django_mailman3.urls')),
3535
path('accounts/', include('allauth.urls')),
3636
path('admin/', admin.site.urls),

templates/vhost.j2

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
upstream myapp {
3+
server unix:/run/mailman3-web.sock;
4+
}
5+
6+
server {
7+
listen 80 default_server;
8+
server_name {{ mailman3_web_url }};
9+
#return 301 https://cpp.al$request_uri;
10+
location '/.well-known/acme-challenge' {
11+
default_type "text/plain";
12+
root /var/www/letsencrypt;
13+
}
14+
location / {
15+
return 301 https://$host$request_uri;
16+
}
17+
}
18+
19+
server {
20+
listen 443 ssl default_server;
21+
listen [::]:443 ssl default_server;
22+
server_name {{ mailman3_web_url }};
23+
location /static/ {
24+
alias /var/lib/mailman3/web/static/;
25+
}
26+
location / {
27+
proxy_pass http://myapp;
28+
proxy_set_header Host $host;
29+
proxy_set_header X-Forwarded-For $remote_addr;
30+
}
31+
32+
{{ mailman3_nginx_ssl_certs }}
33+
ssl_session_cache shared:le_nginx_SSL:10m;
34+
ssl_session_timeout 1440m;
35+
ssl_session_tickets off;
36+
ssl_protocols TLSv1.2 TLSv1.3;
37+
ssl_prefer_server_ciphers off;
38+
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";
39+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
40+
}
41+

0 commit comments

Comments
 (0)