Fixes #798. Dedicated set of tasks to perform a mailman upgrade.

This commit is contained in:
Andrea Dell'Amico 2020-06-26 17:48:21 +02:00
parent a197ac7043
commit af62d73ac5
6 changed files with 303 additions and 246 deletions

View File

@ -1,5 +1,7 @@
---
mailman_upgrade_all_the_distribution: False
mailman_user: 'mailman'
mailman_postorius_user: '{{ mailman_user }}'
mailman_srv_user: '{{ mailman_user }}'
mailman_api_user: 'restadmin'
mailman_home: '/opt/{{ mailman_user }}'
@ -22,7 +24,7 @@ mailman_logrotate_retain: 10
# Documentation that must be followed to configure the social auth providers
# https://django-allauth.readthedocs.io/en/latest/installation.html
mailman_use_social_account_providers: False
mailman_postorious_social_auth_providers:
mailman_postorius_social_auth_providers:
- 'django_mailman3.lib.auth.fedora'
- 'allauth.socialaccount.providers.openid'
- 'allauth.socialaccount.providers.github'
@ -43,7 +45,7 @@ mailman_rh_dependencies:
- git
- lynx
mailman_postorious_rh_dependencies:
mailman_postorius_rh_dependencies:
- uwsgi-logger-systemd
- uwsgi-plugin-python36
- uwsgi
@ -64,6 +66,13 @@ mailman_pip_packages:
- { pkg: 'psycopg2-binary' }
- { pkg: 'whoosh' }
mailman_pip_packages_to_upgrade:
- { pkg: 'mailman' }
- { pkg: 'postorius' }
- { pkg: 'hyperkitty' }
- { pkg: 'mailman-hyperkitty' }
- { pkg: 'mailmanclient' }
mailman_db: postgresql
mailman_db_host: 'localhost'
mailman_db_name: mailman
@ -105,32 +114,32 @@ mailman_antispam_header_checks:
mailman_start_nntp_runner: 'no'
mailman_repository: 'https://gitlab.com/mailman/mailman-suite.git'
mailman_postorious_var_dir: var
mailman_postorious_log_base_dir: log
mailman_postorious_log_dest_dir: mailmansuite
mailman_postorious_log_dir: '/{{ mailman_postorious_var_dir }}/{{ mailman_postorious_log_base_dir }}/{{ mailman_postorious_log_dest_dir }}'
mailman_postorious_dir: '{{ mailman_home }}/mailman-suite/mailman-suite_project'
mailman_postorious_http_port: 8000
mailman_postorius_var_dir: var
mailman_postorius_log_base_dir: log
mailman_postorius_log_dest_dir: mailmansuite
mailman_postorius_log_dir: '/{{ mailman_postorius_var_dir }}/{{ mailman_postorius_log_base_dir }}/{{ mailman_postorius_log_dest_dir }}'
mailman_postorius_dir: '{{ mailman_home }}/mailman-suite/mailman-suite_project'
mailman_postorius_http_port: 8000
# 'systemd_logger,logfile,python36'
mailman_postorious_uwsgi_plugins: 'systemd_logger,python36'
mailman_postorius_uwsgi_plugins: 'systemd_logger,python36'
# 1 is the predefined one, that must be deleted
mailman_postorious_site_id: 2
mailman_postorious_allowed_hosts:
mailman_postorius_site_id: 2
mailman_postorius_allowed_hosts:
- 'localhost'
- '{{ ansible_fqdn }}'
mailman_postorious_hyperkitty_acl: "'127.0.0.1', '::1', '{{ ansible_default_ipv4.address }}'"
mailman_postorius_hyperkitty_acl: "'127.0.0.1', '::1', '{{ ansible_default_ipv4.address }}'"
mailman_postorious_settings_files:
mailman_postorius_settings_files:
- { name: 'manage.py', perms: '0750' }
- { name: 'settings.py', perms: '0440' }
- { name: 'wsgi.py', perms: '0440' }
mailman_postorious_db_engine: 'django.db.backends.postgresql_psycopg2'
mailman_postorious_db_name: mailmansuite
mailman_postorious_db_user: mailmansuite_u
# mailman_postorious_db_password:
mailman_postorious_db_host: 'localhost'
mailman_postorious_db_port: ''
mailman_postorius_db_engine: 'django.db.backends.postgresql_psycopg2'
mailman_postorius_db_name: mailmansuite
mailman_postorius_db_user: mailmansuite_u
# mailman_postorius_db_password:
mailman_postorius_db_host: 'localhost'
mailman_postorius_db_port: ''
mailman_use_hyperkitty_archiver: True
#
# @hourly apache django-admin runjobs hourly --pythonpath /path/to/project --settings settings
@ -140,14 +149,14 @@ mailman_use_hyperkitty_archiver: True
# @yearly apache django-admin runjobs yearly --pythonpath /path/to/project --settings settings
# * * * * * apache django-admin runjobs minutely --pythonpath /path/to/project --settings settings
# 2,17,32,47 * * * * apache django-admin runjobs quarter_hourly --pythonpath /path/to/project --settings settings
mailman_postorious_cronjob_frequency:
mailman_postorius_cronjob_frequency:
- 'yearly'
- 'monthly'
- 'weekly'
- 'daily'
- 'hourly'
mailman_postorious_cronjob_special_times:
mailman_postorius_cronjob_special_times:
- 'quarter_hourly'
- 'minutely'

6
handlers/main.yml Normal file
View File

@ -0,0 +1,6 @@
---
- name: Restart postorius
service: name=uwsgi state=restarted
- name: Restart mailman
service: name=mailman state=restarted

View File

@ -0,0 +1,37 @@
---
- name: Upgrade the mailman, postorius and hyperkitty packages
block:
- name: Install the required packages in the mailman virtualenv
become: True
become_user: '{{ mailman_user }}'
pip:
executable: '{{ mailman_bindir }}/pip3'
virtualenv_command: '/bin/virtualenv-3'
virtualenv_site_packages: no
name: '{{ item.pkg }}'
extra_args: "{{ item.extra_args | default('') }}"
state: 'latest'
editable: no
with_items: '{{ mailman_pip_packages_to_upgrade }}'
notify:
- Restart mailman
- Restart postorius
- name: Remove the postorius static files
file: dest='{{ mailman_postorius_dir }}/static' state=absent
- name: Recreate the postorius static and locale directories
file: dest='{{ mailman_postorius_dir }}/{{ item }}' state=directory owner={{ mailman_postorius_user }} group={{ mailman_postorius_user }}
with_items:
- 'static'
- 'locale'
- name: Setup postorius and hyperkitty
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_postorius_dir }}' && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py migrate && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py compilemessages && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py collectstatic
args:
creates: '{{ mailman_postorius_dir }}/static/admin/js/actions.js'
notify: Restart postorius
when: mailman_upgrade_all_the_distribution
tags: [ 'mailman_upgrade' ]

134
tasks/mailman.yml Normal file
View File

@ -0,0 +1,134 @@
---
- name: Install the distribution dependencies
block:
- name: mailman distribution dependencies, RH/CentOS
yum: pkg={{ mailman_rh_dependencies }} state=present
- name: postorius distribution dependencies, RH/CentOS
yum: pkg={{ mailman_postorius_rh_dependencies }} state=present
when: ansible_distribution_file_variety == "RedHat"
tags: [ 'mailman' ]
- name: Create the mailman user
block:
- name: mailman user
user: name={{ mailman_srv_user }} createhome=no shell=/usr/sbin/nologin system=yes comment='Mailman User' generate_ssh_key=yes home={{ mailman_home }}
- name: Create the mailman user directory
file: dest={{ mailman_home }} state=directory mode=0755 owner={{ mailman_srv_user }} group={{ mailman_srv_user }}
when: ansible_distribution_file_variety == "RedHat"
tags: [ 'mailman' ]
- name: Create the mailman environment
block:
- name: Mailman directory tree
file: dest={{ item }} state=directory owner={{ mailman_user }} group={{ mailman_user }}
with_items:
- '{{ mailman_conf_dir }}'
- '{{ mailman_var_dir }}'
- '{{ mailman_log_dir }}'
- '{{ mailman_lock_dir }}'
- '{{ mailman_spool_dir }}'
- name: Create the mailman virtualenv. Manually, because python 3.6
become: True
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_home }}' && python3 -m venv '{{ mailman_virtualenv_name }}'
args:
creates: '{{ mailman_bindir }}/activate'
- name: Install the required packages in the mailman virtualenv
become: True
become_user: '{{ mailman_user }}'
pip:
executable: '{{ mailman_bindir }}/pip3'
virtualenv_command: '/bin/virtualenv-3'
virtualenv_site_packages: no
name: '{{ item.pkg }}'
extra_args: "{{ item.extra_args | default('') }}"
version: "{{ item.version | default('') }}"
editable: no
with_items: '{{ mailman_pip_packages }}'
- name: Install the mailman and postfix configuration files
template: src={{ item }}.j2 dest={{ mailman_conf_dir }}/{{ item }} owner=root group={{ mailman_user }} mode=0440
with_items:
- 'mailman.cfg'
- 'postfix-mailman.cfg'
register: mailman_conf_install
- name: The mailman executables must be visible to systemd
file: src={{ mailman_bindir }}/{{ item }} dest=/sbin/{{ item }} state=link
with_items:
- 'mailman'
- 'master'
- 'runner'
- 'dkimsign'
- 'arcverify'
- 'arcsign'
- 'dknewkey'
- 'dkimverify'
- 'falcon-print-routes'
- 'falcon-bench'
- 'mako-render'
- 'alembic'
- name: Create the tmpfile entry for the mailman lock directory
template: src=tmpfile_mailman.conf.j2 dest=/usr/lib/tmpfiles.d/mailman.conf owner=root group=root mode=0644
- name: Install the mailman startup unit
template: src=mailman.service.systemd.j2 dest=/lib/systemd/system/mailman.service owner=root group=root mode=0644
register: mailman_unit_install
- name: Reload the systemd configuration
systemd: daemon_reload=yes
when: mailman_unit_install is changed
tags: [ 'mailman', 'mailman_conf' ]
- name: Manage the mailman service
block:
- name: Ensure that the mailman service is started and enabled
service: name=mailman state=started enabled=yes
- name: Restart mailman if the configuration changed
service: name=mailman state=restarted
when: mailman_conf_install is changed
- name: Restart mailman if the configuration changed
service: name=mailman state=restarted
when: mailman_hyperkitty_install is changed
- name: Install the mailman and mailmansuite logrotate configurations
template: src={{ item }}-logrotate.j2 dest=/etc/logrotate.d/{{ item }} owner=root mode=0444
with_items:
- 'mailman'
- 'mailman-postorius'
tags: [ 'mailman', 'mailman_conf' ]
- name: Add the maintenance cron jobs
block:
- name: Add a daily cron job that sends digests
cron:
job: "{{ mailman_bindir }}/mailman digests --periodic > {{ mailman_log_dir }}/mailman_cron_digest.log 2>&1"
special_time: daily
user: '{{ mailman_user }}'
name: "Mailman digests"
cron_file: 'mailman-digests'
state: present
- name: Add a daily cron job that sends notifications to the list administrators and list owners
cron:
job: "{{ mailman_bindir }}/mailman notify > {{ mailman_log_dir }}/mailman_cron_notifications.log 2>&1"
minute: '0'
hour: '7'
user: '{{ mailman_user }}'
name: "Mailman notifications"
cron_file: 'mailman-notifications'
state: present
tags: [ 'mailman', 'mailman_conf', 'mailman_cron' ]

View File

@ -1,226 +1,5 @@
---
- name: Install the distribution dependencies
block:
- name: mailman distribution dependencies, RH/CentOS
yum: pkg={{ mailman_rh_dependencies }} state=present
- name: postorious distribution dependencies, RH/CentOS
yum: pkg={{ mailman_postorious_rh_dependencies }} state=present
when: ansible_distribution_file_variety == "RedHat"
tags: [ 'mailman' ]
- name: Create the mailman user
block:
- name: mailman user
user: name={{ mailman_srv_user }} createhome=no shell=/usr/sbin/nologin system=yes comment='Mailman User' generate_ssh_key=yes home={{ mailman_home }}
- name: Create the mailman user directory
file: dest={{ mailman_home }} state=directory mode=0755 owner={{ mailman_srv_user }} group={{ mailman_srv_user }}
when: ansible_distribution_file_variety == "RedHat"
tags: [ 'mailman' ]
- name: Create the mailman environment
block:
- name: Mailman directory tree
file: dest={{ item }} state=directory owner={{ mailman_user }} group={{ mailman_user }}
with_items:
- '{{ mailman_conf_dir }}'
- '{{ mailman_var_dir }}'
- '{{ mailman_log_dir }}'
- '{{ mailman_lock_dir }}'
- '{{ mailman_spool_dir }}'
- name: Create the mailman virtualenv. Manually, because python 3.6
become: True
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_home }}' && python3 -m venv '{{ mailman_virtualenv_name }}'
args:
creates: '{{ mailman_bindir }}/activate'
- name: Install the required packages in the mailman virtualenv
become: True
become_user: '{{ mailman_user }}'
pip:
executable: '{{ mailman_bindir }}/pip3'
virtualenv_command: '/bin/virtualenv-3'
virtualenv_site_packages: no
name: '{{ item.pkg }}'
extra_args: "{{ item.extra_args | default('') }}"
version: "{{ item.version | default('') }}"
editable: no # not required. Pass the editable flag.
with_items: '{{ mailman_pip_packages }}'
- name: Install the mailman and postfix configuration files
template: src={{ item }}.j2 dest={{ mailman_conf_dir }}/{{ item }} owner=root group={{ mailman_user }} mode=0440
with_items:
- 'mailman.cfg'
- 'postfix-mailman.cfg'
register: mailman_conf_install
- name: The mailman executables must be visible to systemd
file: src={{ mailman_bindir }}/{{ item }} dest=/sbin/{{ item }} state=link
with_items:
- 'mailman'
- 'master'
- 'runner'
- 'dkimsign'
- 'arcverify'
- 'arcsign'
- 'dknewkey'
- 'dkimverify'
- 'falcon-print-routes'
- 'falcon-bench'
- 'mako-render'
- 'alembic'
- name: Create the tmpfile entry for the mailman lock directory
template: src=tmpfile_mailman.conf.j2 dest=/usr/lib/tmpfiles.d/mailman.conf owner=root group=root mode=0644
- name: Install the mailman startup unit
template: src=mailman.service.systemd.j2 dest=/lib/systemd/system/mailman.service owner=root group=root mode=0644
register: mailman_unit_install
- name: Reload the systemd configuration
systemd: daemon_reload=yes
when: mailman_unit_install is changed
tags: [ 'mailman', 'mailman_conf' ]
- name: Create the postorious and hyperkitty environments
block:
- name: Set httpd_can_network_connect flag on and keep it persistent across reboots
seboolean:
name: httpd_can_network_connect
state: yes
persistent: yes
- name: Create the Postorious log directory
file: dest={{ item }} state=directory owner={{ mailman_user }} group={{ mailman_user }}
with_items:
- '{{ mailman_postorious_log_dir }}'
- name: Download the mailmansuite repository
become: True
become_user: '{{ mailman_user }}'
git:
dest: '{{ mailman_home }}/mailman-suite'
repo: '{{ mailman_repository }}'
force: yes
track_submodules: no
clone: yes
update: yes
recursive: yes
- name: Install the postorious setting files
become: True
become_user: '{{ mailman_user }}'
template: src=postorious_{{ item.name }}.j2 dest={{ mailman_postorious_dir }}/{{ item.name }} mode={{ item.perms }}
with_items: '{{ mailman_postorious_settings_files }}'
register: postorious_conf
- name: Install the UWSGI configuration
template: src=postorious_{{ item }}.j2 dest=/etc/{{ item }} mode=0640
with_items:
- 'uwsgi.ini'
- name: Setup postorius and hyperkitty
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_postorious_dir }}' && mkdir -p locale && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py migrate && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py compilemessages && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py collectstatic
args:
creates: '{{ mailman_postorious_dir }}/static/admin/js/actions.js'
- name: Ensure that the UWSGI postorius service is started and enabled
service: name=uwsgi state=started enabled=yes
- name: Restart the UWSGI service if needed
service: name=uwsgi state=restarted
when: postorious_conf is changed
- name: Install the hyperkitty configuration file
template: src=mailman-hyperkitty.cfg.j2 dest={{ mailman_conf_dir }}/mailman-hyperkitty.cfg owner=root group={{ mailman_user }} mode=0440
when: mailman_use_hyperkitty_archiver | bool
register: mailman_hyperkitty_install
tags: [ 'mailman', 'postorious', 'hyperkitty', 'mailman_conf' ]
- name: Setup the postorius cron jobs
block:
- name: add a cron job that syncs the mailman core and postorius settings
cron:
job: "{{ mailman_postorious_dir }}/manage.py runjobs {{ item }} > {{ mailman_postorious_log_dir }}/runjobs-{{ item }}.log 2>&1"
special_time: '{{ item }}'
user: '{{ mailman_user }}'
name: "postorious / hyperkitty runjobs {{ item }}"
cron_file: 'postorius-runjobs-{{ item }}'
state: present
disabled: no
with_items: '{{ mailman_postorious_cronjob_frequency }}'
- name: postorius cron job that runs every 15 minutes
cron:
job: "{{ mailman_postorious_dir }}/manage.py runjobs quarter_hourly > {{ mailman_postorious_log_dir }}/runjobs-quarter_hourly.log 2>&1"
minute: "3,18,33,48"
user: '{{ mailman_user }}'
name: "postorious / hyperkitty runjobs quarter_hourly"
cron_file: 'postorius-runjobs-quarter_hourly'
disabled: no
state: present
- name: postorius cron job that runs every minute
cron:
job: "{{ mailman_postorious_dir }}/manage.py runjobs minutely > {{ mailman_postorious_log_dir }}/runjobs-minutely.log 2>&1"
minute: "*"
user: '{{ mailman_user }}'
name: "postorious / hyperkitty runjobs minutely"
cron_file: 'postorius-runjobs-minutely'
state: present
disabled: no
tags: [ 'mailman', 'postorious', 'hyperkitty', 'mailman_conf', 'postorius_cron' ]
- name: Manage the mailman service
block:
- name: Ensure that the mailman service is started and enabled
service: name=mailman state=started enabled=yes
- name: Restart mailman if the configuration changed
service: name=mailman state=restarted
when: mailman_conf_install is changed
- name: Restart mailman if the configuration changed
service: name=mailman state=restarted
when: mailman_hyperkitty_install is changed
- name: Install the mailman and mailmansuite logrotate configurations
template: src={{ item }}-logrotate.j2 dest=/etc/logrotate.d/{{ item }} owner=root mode=0444
with_items:
- 'mailman'
- 'mailman-postorious'
tags: [ 'mailman', 'postorious', 'hyperkitty', 'mailman_conf' ]
- name: Add the maintenance cron jobs
block:
- name: Add a daily cron job that sends digests
cron:
job: "{{ mailman_bindir }}/mailman digests --periodic > {{ mailman_log_dir }}/mailman_cron_digest.log 2>&1"
special_time: daily
user: '{{ mailman_user }}'
name: "Mailman digests"
cron_file: 'mailman-digests'
state: present
- name: Add a daily cron job that sends notifications to the list administrators and list owners
cron:
job: "{{ mailman_bindir }}/mailman notify > {{ mailman_log_dir }}/mailman_cron_notifications.log 2>&1"
minute: '0'
hour: '7'
user: '{{ mailman_user }}'
name: "Mailman notifications"
cron_file: 'mailman-notifications'
state: present
tags: [ 'mailman', 'postorious', 'hyperkitty', 'mailman_conf', 'mailman_cron' ]
- import_tasks: mailman.yml
- import_tasks: postorius-hyperkitty.yml
- import_tasks: mailman-postorius-hyperkitty-upgrade.yml
when: mailman_upgrade_all_the_distribution

View File

@ -0,0 +1,92 @@
---
- name: Create the postorius and hyperkitty environments
block:
- name: Set httpd_can_network_connect flag on and keep it persistent across reboots
seboolean:
name: httpd_can_network_connect
state: yes
persistent: yes
- name: Create the postorius log directory
file: dest={{ item }} state=directory owner={{ mailman_user }} group={{ mailman_user }}
with_items:
- '{{ mailman_postorius_log_dir }}'
- name: Download the mailmansuite repository
become: True
become_user: '{{ mailman_user }}'
git:
dest: '{{ mailman_home }}/mailman-suite'
repo: '{{ mailman_repository }}'
force: yes
track_submodules: no
clone: yes
update: yes
recursive: yes
- name: Install the postorius setting files
become: True
become_user: '{{ mailman_user }}'
template: src=postorius_{{ item.name }}.j2 dest={{ mailman_postorius_dir }}/{{ item.name }} mode={{ item.perms }}
with_items: '{{ mailman_postorius_settings_files }}'
register: postorius_conf
- name: Install the UWSGI configuration
template: src=postorius_{{ item }}.j2 dest=/etc/{{ item }} mode=0640
with_items:
- 'uwsgi.ini'
- name: Setup postorius and hyperkitty
become_user: '{{ mailman_user }}'
shell: cd '{{ mailman_postorius_dir }}' && mkdir -p locale && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py migrate && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py compilemessages && {{ mailman_home }}/{{ mailman_virtualenv_name }}/bin/python3 manage.py collectstatic
args:
creates: '{{ mailman_postorius_dir }}/static/admin/js/actions.js'
- name: Ensure that the UWSGI postorius service is started and enabled
service: name=uwsgi state=started enabled=yes
- name: Restart the UWSGI service if needed
service: name=uwsgi state=restarted
when: postorius_conf is changed
- name: Install the hyperkitty configuration file
template: src=mailman-hyperkitty.cfg.j2 dest={{ mailman_conf_dir }}/mailman-hyperkitty.cfg owner=root group={{ mailman_user }} mode=0440
when: mailman_use_hyperkitty_archiver | bool
register: mailman_hyperkitty_install
tags: [ 'mailman', 'postorius', 'hyperkitty', 'mailman_conf' ]
- name: Setup the postorius cron jobs
block:
- name: add a cron job that syncs the mailman core and postorius settings
cron:
job: "{{ mailman_postorius_dir }}/manage.py runjobs {{ item }} > {{ mailman_postorius_log_dir }}/runjobs-{{ item }}.log 2>&1"
special_time: '{{ item }}'
user: '{{ mailman_user }}'
name: "postorius / hyperkitty runjobs {{ item }}"
cron_file: 'postorius-runjobs-{{ item }}'
state: present
disabled: no
with_items: '{{ mailman_postorius_cronjob_frequency }}'
- name: postorius cron job that runs every 15 minutes
cron:
job: "{{ mailman_postorius_dir }}/manage.py runjobs quarter_hourly > {{ mailman_postorius_log_dir }}/runjobs-quarter_hourly.log 2>&1"
minute: "3,18,33,48"
user: '{{ mailman_user }}'
name: "postorius / hyperkitty runjobs quarter_hourly"
cron_file: 'postorius-runjobs-quarter_hourly'
disabled: no
state: present
- name: postorius cron job that runs every minute
cron:
job: "{{ mailman_postorius_dir }}/manage.py runjobs minutely > {{ mailman_postorius_log_dir }}/runjobs-minutely.log 2>&1"
minute: "*"
user: '{{ mailman_user }}'
name: "postorius / hyperkitty runjobs minutely"
cron_file: 'postorius-runjobs-minutely'
state: present
disabled: no
tags: [ 'mailman', 'postorius', 'hyperkitty', 'mailman_conf', 'postorius_cron' ]