forked from ISTI-ansible-roles/ansible-role-mailman
244 lines
8.7 KiB
YAML
244 lines
8.7 KiB
YAML
---
|
|
- 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
|
|
tags: [ 'mailman', 'mailman_conf', 'mailman_main_conf' ]
|
|
|
|
- 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
|
|
tags: [ 'mailman', 'mailman_conf', 'mailman_main_conf' ]
|
|
|
|
- name: Restart mailman if the configuration changed
|
|
service: name=mailman state=restarted
|
|
when: mailman_hyperkitty_install is changed
|
|
|
|
- name: Wait for the Mailman LMTP listener
|
|
ansible.builtin.wait_for:
|
|
host: '{{ mailman_lmtp_host }}'
|
|
port: '{{ mailman_lmtp_port }}'
|
|
state: started
|
|
sleep: 1
|
|
timeout: '{{ mailman_weekly_verified_restart_start_timeout }}'
|
|
when: not ansible_check_mode
|
|
|
|
- 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: Configure the verified weekly Mailman restart
|
|
block:
|
|
- name: Install the verified Mailman restart script
|
|
ansible.builtin.template:
|
|
src: mailman-verified-restart.sh.j2
|
|
dest: /usr/local/sbin/mailman-verified-restart
|
|
owner: root
|
|
group: root
|
|
mode: '0750'
|
|
|
|
- name: Install the verified Mailman restart service
|
|
ansible.builtin.template:
|
|
src: mailman-verified-restart.service.systemd.j2
|
|
dest: /etc/systemd/system/mailman-verified-restart.service
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
register: mailman_verified_restart_service_install
|
|
|
|
- name: Install the weekly Mailman restart timer
|
|
ansible.builtin.template:
|
|
src: mailman-verified-restart.timer.systemd.j2
|
|
dest: /etc/systemd/system/mailman-verified-restart.timer
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
register: mailman_verified_restart_timer_install
|
|
|
|
- name: Reload systemd after installing the restart units
|
|
ansible.builtin.systemd:
|
|
daemon_reload: true
|
|
when: >-
|
|
mailman_verified_restart_service_install is changed or
|
|
mailman_verified_restart_timer_install is changed
|
|
|
|
- name: Enable and start the weekly Mailman restart timer
|
|
ansible.builtin.systemd:
|
|
name: mailman-verified-restart.timer
|
|
state: started
|
|
enabled: true
|
|
|
|
when: mailman_enable_weekly_verified_restart | bool
|
|
tags: [ 'mailman', 'mailman_conf', 'mailman_weekly_restart' ]
|
|
|
|
- name: Seed header matches on lists without existing rules
|
|
block:
|
|
- name: Create the Mailman administration scripts directory
|
|
ansible.builtin.file:
|
|
path: '{{ mailman_conf_dir }}/scripts'
|
|
state: directory
|
|
owner: root
|
|
group: '{{ mailman_user }}'
|
|
mode: '0750'
|
|
|
|
- name: Install the list header matches seed script
|
|
ansible.builtin.template:
|
|
src: seed-empty-list-header-matches.py.j2
|
|
dest: '{{ mailman_conf_dir }}/scripts/seed_empty_list_header_matches.py'
|
|
owner: root
|
|
group: '{{ mailman_user }}'
|
|
mode: '0440'
|
|
|
|
- name: Add header matches only to lists without rules
|
|
become: true
|
|
become_user: '{{ mailman_user }}'
|
|
ansible.builtin.command:
|
|
argv:
|
|
- '{{ mailman_bindir }}/mailman'
|
|
- -C
|
|
- '{{ mailman_conf_dir }}/mailman.cfg'
|
|
- shell
|
|
- --run
|
|
- seed_empty_list_header_matches.apply
|
|
- --listspec
|
|
- '^.*'
|
|
environment:
|
|
PYTHONPATH: '{{ mailman_conf_dir }}/scripts'
|
|
register: mailman_seed_header_matches_result
|
|
changed_when: "'CHANGED ' in mailman_seed_header_matches_result.stdout"
|
|
|
|
when:
|
|
- not ansible_check_mode
|
|
- mailman_seed_empty_list_header_matches | bool
|
|
- mailman_empty_list_header_matches | length > 0
|
|
tags: [ 'mailman', 'mailman_conf', 'mailman_header_matches' ]
|
|
|
|
- name: Add the maintenance cron jobs
|
|
tags: ['mailman', 'mailman_conf', 'mailman_cron']
|
|
block:
|
|
- name: Add a daily cron job that sends digests
|
|
cron:
|
|
job: "{{ mailman_bindir }}/mailman -C {{ mailman_conf_dir }}/mailman.cfg 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 -C {{ mailman_conf_dir }}/mailman.cfg 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: "{% if mailman_enable_daily_notifications %}present{% else %}absent{% endif %}"
|
|
|
|
- name: Install some default templates
|
|
block:
|
|
- name: Create the 'site' directory and the language subdirs
|
|
file: dest={{ mailman_var_dir }}/templates/site/{{ item }} state=directory owner={{ mailman_user }} group={{ mailman_user}}
|
|
with_items:
|
|
- it
|
|
- en
|
|
|
|
- name: Install the custom templates
|
|
template: src=site/{{ item }}.j2 dest={{ mailman_var_dir }}/templates/site/{{ item }} owner={{ mailman_user }} group={{ mailman_user}}
|
|
with_items: '{{ mailman_custom_templates }}'
|
|
|
|
tags: [ 'mailman', 'mailman_templates' ]
|