---
- name: Dependencies installed
  community.general.pkgng:
    name: py38-matrix-synapse,redis,py38-txredisapi,py38-hiredis,gtar
    state: latest

- name: Synapse enabled
  shell: sysrc synapse_enable="YES"

- name: Nginx config installed
  copy:
    src: nginx.conf
    dest: /usr/local/etc/nginx/locations/matrix.conf
    mode: 0644
  notify: Nginx restarted

- name: Homeserver log config installed
  copy:
    src: matrix.unbl.ink.log.config
    dest: /usr/local/etc/matrix-synapse/matrix.unbl.ink.log.config
    owner: root
    mode: 0644

- name: Homeserver signing key installed
  template:
    src: matrix.unbl.ink.signing.key.j2
    dest: /usr/local/etc/matrix-synapse/matrix.unbl.ink.signing.key
    owner: root
    mode: 0644

- name: Homeserver media directory exists
  file:
    path: /usr/local/etc/matrix-synapse/media_store
    owner: synapse
    mode: 0755
    state: directory

- name: Homeserver config installed
  template:
    src: homeserver.yaml.j2
    dest: /usr/local/etc/matrix-synapse/homeserver.yaml
    owner: root
    mode: 0644
  notify: Synapse restarted

- name: Element fetched and installed
  unarchive:
    src: https://github.com/vector-im/element-web/releases/download/v1.9.4/element-v1.9.4.tar.gz
    owner: www
    dest: /usr/local/www/
    remote_src: yes

- name: Element config file installed
  copy:
    src: config.json
    dest: /usr/local/www/element-v1.9.4/config.json
    owner: www
    mode: 0644
