matrix-bridge-facebook/tasks/main.yml

110 lines
2.7 KiB
YAML
Raw Normal View History

2022-03-06 16:35:31 +01:00
---
- name: Setup postgres
include_role:
name: postgre
vars:
postgres_users:
- name: bridge_facebook_user
password: "{{ matrix_bridge_facebook_postgre_user_pwd }}"
databases:
- name: bridge_facebook
owner: bridge_facebook_user
local: C
template: template0
no_log: true
- name: Install dependencies
apt:
name:
- python3
- python3-virtualenv
- python3-pip
state: latest
update_cache: true
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Create the mautrix-facebook user
user:
name: mautrix-facebook
home: /opt/mautrix-facebook
password_lock: yes
system: yes
- name: Install bridge
become: yes
become_user: mautrix-facebook
pip:
name: mautrix-facebook[animated_stickers]
virtualenv: /opt/mautrix-facebook
virtualenv_command: virtualenv
virtualenv_python: /usr/bin/python3
2022-03-06 17:28:17 +01:00
- name: Check if the bridge is already configured
stat:
path: /opt/mautrix-facebook/config.yaml
register: register_config
- name: Set read token variable
block:
- name: read config file
slurp:
src: /opt/mautrix-facebook/config.yaml
register: encoded_facebook_config
- name: decode config file
set_fact:
facebook_config: "{{ encoded_facebook_config.content | b64decode | from_yaml }}"
2022-03-06 17:38:35 +01:00
- name: extract tokens
set_fact:
2022-03-06 17:43:12 +01:00
matrix_bridge_facebook_as_token: "{{ facebook_config.appservice.as_token }}"
2022-03-06 21:18:17 +01:00
matrix_bridge_facebook_hs_token: "{{ facebook_config.appservice.hs_token }}"
2022-03-06 17:28:17 +01:00
when: register_config.stat.exists
2022-03-06 16:35:31 +01:00
- name: Configure the bridge
template:
src: config.yaml
dest: /opt/mautrix-facebook/config.yaml
owner: mautrix-facebook
group: nogroup
mode: '0600'
notify: Restart the facebook bridge
no_log: true
- name: Generate facebook-registration.yaml
become: yes
become_user: mautrix-facebook
shell:
cmd: "/opt/mautrix-facebook/bin/python -m mautrix_facebook -g"
chdir: /opt/mautrix-facebook
creates: /opt/mautrix-facebook/registration.yaml
notify: Restart synapse
no_log: true
- name: Copy config for synapse
file:
src: /opt/mautrix-facebook/registration.yaml
2022-03-06 20:04:43 +01:00
dest: /etc/matrix-synapse/registrations/facebook-registration.yaml
2022-03-06 16:35:31 +01:00
state: link
- name: Ensure the log directory exists
file:
path: /var/log/bridge_facebook
state: directory
group: nogroup
owner: mautrix-facebook
mode: u=rwx,g=rx,o=
- name: Copy the daemon configuration
template:
src: bridge_facebook.service
dest: /etc/systemd/system/bridge_facebook.service
notify: Restart the facebook bridge
- name: Enable the daemon
systemd:
name: bridge_facebook
state: started
enabled: yes