213 lines
6.2 KiB
YAML
213 lines
6.2 KiB
YAML
---
|
|
- name: Install chat
|
|
hosts: all
|
|
become: true
|
|
tasks:
|
|
- name: Install deps
|
|
apt:
|
|
name:
|
|
- git
|
|
- vim
|
|
- lighttpd
|
|
- sudo
|
|
state: present
|
|
update_cache: yes
|
|
when: not ( is_vmdb2 | bool )
|
|
|
|
# install Go
|
|
# # - name: Download Go tarball
|
|
# get_url:
|
|
# url: "https://go.dev/dl/go{{ go_version }}.linux-{{ go_arch_map[ansible_architecture] }}.tar.gz"
|
|
# dest: /tmp/go.tar.gz
|
|
# mode: '0644'
|
|
#
|
|
# - name: Extract Go to /usr/local
|
|
# unarchive:
|
|
# src: /tmp/go.tar.gz
|
|
# dest: /usr/local
|
|
# remote_src: yes
|
|
# creates: /usr/local/go
|
|
#
|
|
# - name: Ensure Go path is in .profile
|
|
# lineinfile:
|
|
# path: "/home/{{ butter_user }}/.profile"
|
|
# line: 'PATH=$PATH:/usr/local/go/bin'
|
|
# insertafter: EOF
|
|
# state: present
|
|
# create: yes
|
|
#
|
|
# - name: Remove existing dendrite directory if it exists
|
|
# file:
|
|
# path: "/home/{{ butter_user }}/dendrite"
|
|
# state: absent
|
|
#
|
|
# - name: Clone dendrite repo
|
|
# git:
|
|
# repo: https://github.com/matrix-org/dendrite
|
|
# dest: "/home/{{ butter_user }}/dendrite"
|
|
# version: v0.13.7
|
|
# force: yes
|
|
# update: no
|
|
# depth: 1
|
|
#
|
|
# - name: Build dendrite
|
|
# command: /usr/local/go/bin/go build -o bin/ ./cmd/...
|
|
# args:
|
|
# chdir: "/home/{{ butter_user }}/dendrite"
|
|
#
|
|
#
|
|
|
|
- name: copy Dendrite dir to target
|
|
copy:
|
|
src: "dendrite/"
|
|
dest: "/home/{{ butter_user }}/dendrite"
|
|
owner: "{{ butter_user }}"
|
|
group: "{{ butter_user }}"
|
|
|
|
- name: Ensure butter_user owns Dendrite directory
|
|
file:
|
|
path: "/home/{{ butter_user }}/dendrite"
|
|
state: directory
|
|
recurse: yes
|
|
owner: "{{ butter_user }}"
|
|
group: "{{ butter_user }}"
|
|
mode: "0755"
|
|
|
|
- name: Generate Matrix signing key
|
|
command: ./bin/generate-keys --private-key matrix_key.pem
|
|
args:
|
|
chdir: "/home/{{ butter_user }}/dendrite"
|
|
|
|
- name: Generate self-signed TLS certificate (optional)
|
|
command: ./bin/generate-keys --tls-cert server.crt --tls-key server.key
|
|
args:
|
|
chdir: "/home/{{ butter_user }}/dendrite"
|
|
|
|
- name: Download Dendrite config to target
|
|
get_url:
|
|
url: "{{ config_base_url }}/butterbox-dendrite.conf"
|
|
dest: "/home/{{ butter_user }}/dendrite/butterbox-dendrite.conf"
|
|
owner: "{{ butter_user }}"
|
|
group: "{{ butter_user }}"
|
|
mode: '0644'
|
|
|
|
- name: Replace REPLACEME with butter_name in config
|
|
replace:
|
|
path: "/home/{{ butter_user }}/dendrite/butterbox-dendrite.conf"
|
|
regexp: 'REPLACEME'
|
|
replace: "{{ butter_name }}"
|
|
|
|
- name: Replace /home/pi with /home/butter_user in config
|
|
replace:
|
|
path: "/home/{{ butter_user }}/dendrite/butterbox-dendrite.conf"
|
|
regexp: '/pi/'
|
|
replace: "/{{ butter_user }}/"
|
|
|
|
- name: Create log directory for Dendrite
|
|
file:
|
|
path: "/var/log/dendrite"
|
|
state: directory
|
|
owner: "{{ butter_user }}"
|
|
group: "{{ butter_user }}"
|
|
mode: '0755'
|
|
recurse: yes
|
|
|
|
- name: Download dendrite systemd service file
|
|
get_url:
|
|
url: "{{ config_base_url }}/butterbox-dendrite.service"
|
|
dest: /lib/systemd/system/dendrite.service
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
|
|
- name: Replace /home/pi with /home/butter_user in service file
|
|
replace:
|
|
path: /lib/systemd/system/dendrite.service
|
|
regexp: '/pi/'
|
|
replace: "/{{ butter_user }}/"
|
|
|
|
- name: Replace pi with butter_user in service file
|
|
replace:
|
|
path: /lib/systemd/system/dendrite.service
|
|
regexp: 'User=pi'
|
|
replace: "User={{ butter_user }}"
|
|
|
|
- name: Enable dendrite by symlink
|
|
file:
|
|
src: /lib/systemd/system/dendrite.service
|
|
dest: /etc/systemd/system/multi-user.target.wants/dendrite.service
|
|
state: link
|
|
|
|
- name: Ensure butter_user owns Dendrite directory
|
|
file:
|
|
path: "/home/{{ butter_user }}/dendrite"
|
|
state: directory
|
|
recurse: yes
|
|
owner: "{{ butter_user }}"
|
|
group: "{{ butter_user }}"
|
|
mode: "0755"
|
|
|
|
- name: Restart service dendrite, issue daemon-reload to pick up config changes
|
|
ansible.builtin.systemd_service:
|
|
state: restarted
|
|
daemon_reload: true
|
|
name: dendrite
|
|
when: not (is_vmdb2 | bool)
|
|
|
|
- name: Download Matrix reverse proxy config for Lighttpd
|
|
get_url:
|
|
url: "{{ config_base_url }}/50-matrix-reverse-proxy.conf"
|
|
dest: /etc/lighttpd/conf-available/50-matrix-reverse-proxy.conf
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
|
|
- name: Ensure old symlink is removed if it exists
|
|
file:
|
|
path: /etc/lighttpd/conf-enabled/50-matrix-reverse-proxy.conf
|
|
state: absent
|
|
force: true
|
|
|
|
- name: Enable reverse proxy config for Matrix in Lighttpd
|
|
file:
|
|
src: /etc/lighttpd/conf-available/50-matrix-reverse-proxy.conf
|
|
dest: /etc/lighttpd/conf-enabled/50-matrix-reverse-proxy.conf
|
|
state: link
|
|
force: true
|
|
|
|
- name: Start dendrite as user butter_user
|
|
become: yes
|
|
become_user: "{{ butter_user }}"
|
|
shell: |
|
|
nohup /home/{{ butter_user }}/dendrite/bin/dendrite \
|
|
--config /home/{{ butter_user }}/dendrite/butterbox-dendrite.conf \
|
|
-really-enable-open-registration \
|
|
> /var/log/dendrite/dendrite-provision.log 2>&1 &
|
|
args:
|
|
chdir: "/home/{{ butter_user }}"
|
|
when: is_vmdb2 | bool
|
|
|
|
|
|
- name: Wait for Dendrite client API to be available
|
|
wait_for:
|
|
host: "127.0.0.1"
|
|
port: 8008
|
|
delay: 3 # wait a few seconds before first check
|
|
timeout: 60 # give it up to a minute to start
|
|
state: started
|
|
when: is_vmdb2 | bool
|
|
|
|
- name: Copy public room script
|
|
template:
|
|
src: templates/create_public_room.sh.j2
|
|
dest: /home/pi/create_public_room.sh
|
|
mode: '0755'
|
|
|
|
- name: Run the create_public_room.sh script
|
|
command: /home/pi/create_public_room.sh
|
|
register: room_creation
|
|
ignore_errors: false
|
|
|
|
- name: Show room creation output
|
|
debug:
|
|
var: room_creation.stdout
|