ansible/roles/matrix/tasks/main.yml

118 lines
3.8 KiB
YAML
Raw Normal View History

2020-06-21 10:22:01 -05:00
#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: Set up Matrix
block:
- name: Set up repos
block:
- name: Add repo keys
apt_key:
url: "{{ item }}"
loop:
- "https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg"
- name: Add repos
apt_repository:
repo: "{{ item }}"
loop:
- "deb https://packages.matrix.org/debian/ bionic main"
- name: Install packages
apt:
name:
2020-08-01 22:13:43 -05:00
- matrix-synapse-py3
2020-08-01 22:17:14 -05:00
- python3-psycopg2
2020-08-01 20:59:55 -05:00
- name: Set up PostgreSQL
block:
- name: Create DB user
postgresql_user:
name: matrix
2020-08-02 19:43:08 -05:00
password: "{{ matrix.db_password }}"
2020-08-01 20:59:55 -05:00
login_host: "{{ matrix_db_hostname }}"
2020-08-02 19:36:46 -05:00
login_user: "{{ psql.ansible.user }}"
login_password: "{{ psql.ansible.pass }}"
2020-08-01 20:59:55 -05:00
- name: Create DB
postgresql_db:
name: matrix
owner: matrix
lc_collate: C
lc_ctype: C
login_host: "{{ matrix_db_hostname }}"
2020-08-02 19:36:46 -05:00
login_user: "{{ psql.ansible.user }}"
login_password: "{{ psql.ansible.pass }}"
when: matrix_db_hostname is defined
- name: Set up Apache
block:
- name: Template out config
template:
src: "apache2-matrix.conf"
2020-06-22 04:44:14 -05:00
dest: "/etc/apache2/conf-available/matrix.conf"
notify: restart apache
- name: Enable configs
command:
cmd: a2enconf "{{ item }}"
2020-06-22 05:07:25 -05:00
creates: "/etc/apache2/conf-enabled/{{ item }}.conf"
loop:
- matrix
notify: restart apache
- name: Enable modules
command:
cmd: a2enmod "{{ item }}"
creates: "/etc/apache2/mods-enabled/{{ item }}.load"
loop:
- proxy
- proxy_http
notify: restart apache
- name: Template out vhost
template:
src: "apache2-vhost-ssl.conf"
2020-08-02 19:43:08 -05:00
dest: "/etc/apache2/sites-available/{{ matrix.url }}.conf"
2020-06-22 06:33:57 -05:00
notify: restart apache
- name: Create webroot
file:
state: directory
path: "{{ matrix_webroot }}"
- name: Enable site
command:
2020-08-02 19:43:08 -05:00
cmd: "a2ensite {{ matrix.url }}.conf"
creates: "/etc/apache2/sites-enabled/{{ matrix.url }}.conf"
notify: restart apache
- name: Generate certificate
include_role:
name: https
vars:
2020-08-02 19:43:08 -05:00
website_url: "{{ matrix.url }}"
- name: Configure Synapse
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
loop:
2020-06-21 11:28:11 -05:00
- { src: "homeserver.yaml", dest: "/etc/matrix-synapse/homeserver.yaml", mode: "0644" }
- { src: "server_name.yaml", dest: "/etc/matrix-synapse/conf.d/server_name.yaml", mode: "0644" }
2020-06-21 11:12:38 -05:00
notify: restart synapse
2020-06-22 04:08:03 -05:00
- name: Check for secrets
stat: path="/etc/matrix-synapse/conf.d/shared_secrets.yaml"
register: p
- name: Generate secrets
block:
- name: Generate registration_shared_secret
command: pwgen 32 1
register: matrix_reg_secret
2020-06-22 04:09:24 -05:00
- name: Generate turn_shared_secret
command: pwgen 32 1
register: matrix_turn_secret
2020-06-22 04:08:03 -05:00
- name: Template out shared_secrets.yaml
template:
2020-06-22 04:28:38 -05:00
src: "shared_secrets.yaml"
2020-06-22 04:08:03 -05:00
dest: "/etc/matrix-synapse/conf.d/shared_secrets.yaml"
mode: "0640"
owner: "matrix-synapse"
group: "root"
2020-06-22 04:10:32 -05:00
notify: restart synapse
2020-06-22 04:08:03 -05:00
when: not p.stat.exists
2020-06-22 11:05:56 -05:00
- name: Template out backup module
template:
src: "backup.sh"
2020-08-02 19:43:08 -05:00
dest: "/opt/backups/modules/{{ matrix.url }}.sh"
2020-06-22 11:05:56 -05:00
mode: "0600"
2020-06-21 10:22:01 -05:00
become: yes