matrix-bridge-telegram/tasks/main.yml

123 lines
3.1 KiB
YAML
Raw Normal View History

2022-03-23 01:09:49 +01:00
---
- name: Setup postgres
include_role:
name: postgre
vars:
postgres_users:
- name: bridge_telegram_user
password: "{{ matrix_bridge_telegram_postgre_user_pwd }}"
databases:
- name: bridge_telegram
owner: bridge_telegram_user
local: C
template: template0
2022-07-21 21:07:41 +02:00
no_log: "{{ enable_no_log | default('true') }}"
2022-03-23 01:09:49 +01:00
- name: Install dependencies
apt:
name:
- python3
- python3-virtualenv
- python3-pip
- libolm-dev # for encryption
- python3-dev #
- build-essential #
state: latest
update_cache: true
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Create the mautrix-telegram user
user:
name: mautrix-telegram
home: /opt/mautrix-telegram
password_lock: yes
system: yes
- name: Install bridge
become: yes
become_user: mautrix-telegram
pip:
name:
- mautrix-telegram[all]
2022-07-15 05:19:27 +02:00
state: latest
2022-03-23 01:09:49 +01:00
virtualenv: /opt/mautrix-telegram
virtualenv_command: virtualenv
virtualenv_python: /usr/bin/python3
- name: Check if the bridge is already configured
stat:
path: /opt/mautrix-telegram/config.yaml
register: register_config
- name: Set read token variable
block:
- name: read config file
slurp:
src: /opt/mautrix-telegram/config.yaml
register: encoded_config
- name: decode config file
set_fact:
telegram_config: "{{ encoded_config.content | b64decode | from_yaml }}"
- name: extract tokens
set_fact:
matrix_bridge_telegram_as_token: "{{ telegram_config.appservice.as_token }}"
matrix_bridge_telegram_hs_token: "{{ telegram_config.appservice.hs_token }}"
when: register_config.stat.exists
- name: Configure the bridge
template:
src: config.yaml
dest: /opt/mautrix-telegram/config.yaml
owner: mautrix-telegram
group: nogroup
mode: '0600'
notify: Restart the telegram bridge
2022-07-21 21:07:41 +02:00
no_log: "{{ enable_no_log | default('true') }}"
2022-03-23 01:09:49 +01:00
2022-03-23 02:06:47 +01:00
- name: Ensure the log directory exists
file:
path: /var/log/bridge_telegram
state: directory
group: nogroup
owner: mautrix-telegram
mode: u=rwx,g=rx,o=
2022-03-23 01:09:49 +01:00
- name: Generate telegram-registration.yaml
become: yes
become_user: mautrix-telegram
shell:
cmd: "/opt/mautrix-telegram/bin/python -m mautrix_telegram -g"
chdir: /opt/mautrix-telegram
creates: /opt/mautrix-telegram/registration.yaml
notify: Restart synapse
2022-07-21 21:07:41 +02:00
no_log: "{{ enable_no_log | default('true') }}"
2022-03-23 01:09:49 +01:00
- name: Ensure the registration directory exists
file:
path: /etc/matrix-synapse/registrations
state: directory
group: root
owner: root
mode: u=rwx,g=rx,o=rx
- name: Copy registration for synapse
file:
src: /opt/mautrix-telegram/registration.yaml
dest: /etc/matrix-synapse/registrations/telegram-registration.yaml
state: link
- name: Copy the daemon configuration
template:
src: bridge_telegram.service
dest: /etc/systemd/system/bridge_telegram.service
notify: Restart the telegram bridge
- name: Enable the daemon
systemd:
name: bridge_telegram
state: started
enabled: yes