--- - 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 no_log: true - 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] 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 no_log: true - 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 no_log: true - 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: Ensure the log directory exists file: path: /var/log/bridge_telegram state: directory group: nogroup owner: mautrix-telegram mode: u=rwx,g=rx,o= - 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