Skip to content

Commit

Permalink
working on dendrite support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Feb 27, 2024
1 parent 5125972 commit c3399b0
Show file tree
Hide file tree
Showing 21 changed files with 931 additions and 7 deletions.
20 changes: 20 additions & 0 deletions roles/dendrite/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

# see https://github.com/matrix-org/dendrite

dendrite_required_packages: []

dendrite_remove: false

dendrite_db_name: dendrite
dendrite_db_user: dendrite
dendrite_db_password: '{{ [ansible_machine_id, ansible_hostname, "dendrite"] | join | hash("md5") }}'
dendrite_db_role_flags: CREATEDB
dendrite_db_host: /run/postgresql

# see https://docs.gitlab.com/ee/install/installation.html#3-go
# NOTE: version should be tests in gitlab pipeline
# SEE https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/workhorse.gitlab-ci.yml#L30
# https://go.dev/dl/ -> linux-amd64.tar.gz
dendrite_go_version: '1.21.7'
dendrite_go_sha256_checksum: a9bc1ccedbfde059f25b3a2ad81ae4cdf21192ae207dfd3ccbbfe99c3749e233
25 changes: 25 additions & 0 deletions roles/dendrite/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
dependencies:
- role: alphanodes.setup.common
- role: alphanodes.setup.ssl
- role: alphanodes.setup.nginx

galaxy_info:
description: Setup element-web
author: alexandermeindl
company: AlphaNodes GmbH
license: Apache License 2.0
min_ansible_version: '2.14'
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- name: Debian
versions:
- buster
- bullseye
- bookworm
galaxy_tags:
- element
- matrix
24 changes: 24 additions & 0 deletions roles/dendrite/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

- name: Include PostgreSQL tasks
ansible.builtin.include_tasks: postgresql.yml
tags:
- dendrite
- matrix
- postgresql
when: not dendrite_remove | bool

- name: Include setup tasks
ansible.builtin.include_tasks: setup.yml
when: not dendrite_remove | bool
tags:
- dendrite
- matrix

- name: Include remove tasks
ansible.builtin.include_tasks: remove.yml
when: dendrite_remove | bool
tags:
- dendrite
- matrix
- remove
38 changes: 38 additions & 0 deletions roles/dendrite/tasks/nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

- name: Set TLS files for letsencrypt
ansible.builtin.set_fact:
vhost_letsencrypt_cert: "{{ element_web_vhost_letsencrypt_cert }}"
vhost_letsencrypt_key: "{{ element_web_vhost_letsencrypt_key }}"
force_letsencrypt: true
when:
- element_web_vhost_letsencrypt is defined
- element_web_vhost_letsencrypt

- name: Check trusted TLS cert
ansible.builtin.stat:
path: /etc/ssl/certs/{{ element_web_vhost_ssl_cert }}_trusted.crt
register: trusted_cert
when: element_web_vhost_letsencrypt is undefined or not element_web_vhost_letsencrypt

- name: Set TLS files
ansible.builtin.set_fact:
vhost_ssl_cert: "{{ element_web_vhost_ssl_cert }}"
vhost_ssl_with_trusted_cert: "{{ trusted_cert.stat.exists | bool }}"
when: element_web_vhost_letsencrypt is undefined or not element_web_vhost_letsencrypt

- name: Update element web vhost configuration
tags: nginx
ansible.builtin.template:
src: vhost.j2
dest: /etc/nginx/sites-available/element_web.conf
mode: 0644
notify: Reload nginx

- name: Enable element web vhost
tags: nginx
ansible.builtin.file:
src: /etc/nginx/sites-available/element_web.conf
dest: /etc/nginx/sites-enabled/element_web.conf
state: link
notify: Reload nginx
45 changes: 45 additions & 0 deletions roles/dendrite/tasks/postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---

- name: Include postgresql role
ansible.builtin.include_role:
name: alphanodes.setup.postgresql

- name: Create dendrite postgresql database user
become_user: postgres
become: true
community.postgresql.postgresql_user:
name: '{{ dendrite_db_user }}'
password: '{{ dendrite_db_password }}'
role_attr_flags: "{{ dendrite_db_role_flags | default('CREATEDB') }}"
state: present
no_log: true

- name: Be sure pg_trgm extension exists
become_user: postgres
become: true
community.postgresql.postgresql_ext:
name: pg_trgm
db: template1

- name: Be sure btree_gist extension exists
become_user: postgres
become: true
community.postgresql.postgresql_ext:
name: btree_gist
db: template1

- name: Be sure plpgsql extension exists
become_user: postgres
become: true
community.postgresql.postgresql_ext:
name: plpgsql
db: template1

- name: Be sure dendrite postgresql databases exists
become_user: postgres
become: true
community.postgresql.postgresql_db:
name: '{{ dendrite_db_name }}'
owner: '{{ dendrite_db_user }}'
template: template1
state: present
23 changes: 23 additions & 0 deletions roles/dendrite/tasks/remove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: Remove element-web package
ansible.builtin.apt:
name: element-web
purge: true
state: absent

- name: Remove element-web apt repository
ansible.builtin.deb822_repository:
name: element-web
state: absent

- name: Remove configuration files
ansible.builtin.file:
name: '{{ item }}'
state: absent
loop:
- /etc/nginx/sites-available/element-web.conf
- /etc/nginx/sites-enabled/element-web.conf
- /etc/element-web
notify:
- Restart nginx
28 changes: 28 additions & 0 deletions roles/dendrite/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- name: Ensure required packages are installed
ansible.builtin.apt:
name: "{{ dendrite_required_packages }}"
state: present

- name: Include Go role
ansible.builtin.include_role:
name: alphanodes.setup.golang
vars:
golang_version: '{{ dendrite_go_version | default(omit) }}'
golang_sha256_checksum: '{{ dendrite_go_sha256_checksum | default(omit) }}'

- name: Ensure Element configuration installed
ansible.builtin.template:
src: config.json.j2
dest: /etc/element-web/config.json
mode: 0644
owner: root
group: root

- name: Include nginx tasks
ansible.builtin.include_tasks: nginx.yml
when: not dendrite_remove | bool
tags:
- dendrite
- matrix
Loading

0 comments on commit c3399b0

Please sign in to comment.