---
- name: Install gtar, sass, pip, wheel and virtualenv
  package:
    name:
      - gtar
      - rubygem-sass
      - py37-pip
      - py37-wheel
      - py37-virtualenv
      - postgresql12-server
      - postgresql12-client
    state: present

- name: Create mailman group
  group:
    name: mailman
    gid: 91

- name: Create mailman user
  user:
    name: mailman
    uid: 91
    group: mailman
    create_home: no
    comment: Mailman User
    home: /usr/local/mailman
    shell: /usr/sbin/nologin

- name: Install mailman3
  become_user: mailman
  pip:
    name:
      - mailman
      - postorius
      - hyperkitty
      - mailman-hyperkitty
      - uwsgi
      - psycopg2
      - 'Django>=1.11'
    virtualenv_command: virtualenv-3.7
    virtualenv: /usr/local/mailman

- name: Create Mailman3 suite Django project directory
  file:
    path: /usr/local/mailman/suite
    state: directory
    owner: mailman
    group: mailman
    mode: 0755

- name: Install Mailman3 suite
  template:
    dest: '/usr/local/mailman/suite/{{ item.name }}'
    src: '{{ item.name }}.j2'
    mode: '{{ item.mode | default("0444") }}'
    owner: mailman
    group: mailman
  with_items:
    - name: manage.py
      mode: 0555
    - name: settings.py
    - name: urls.py
    - name: wsgi.py
  notify:
    - Restart Mailman suite