commit
65da600426
@ -0,0 +1,24 @@
|
||||
# Setting up Mautrix Hangouts (optional)
|
||||
|
||||
The playbook can install and configure [mautrix-hangouts](https://github.com/tulir/mautrix-hangouts) for you.
|
||||
|
||||
See the project's [documentation](https://github.com/tulir/mautrix-hangouts/wiki#usage) to learn what it does and why it might be useful to you.
|
||||
|
||||
To enable the [Google Hangouts](https://hangouts.google.com/) bridge just use the following playbook configuration:
|
||||
|
||||
|
||||
```yaml
|
||||
matrix_mautrix_hangouts_enabled: true
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Once the bot is enabled you need to start a chat with `Hangouts bridge bot` with handle `@hangoutsbot:YOUR_DOMAIN` (where `YOUR_DOMAIN` is your base domain, not the `matrix.` domain).
|
||||
|
||||
Send `login` to the bridge bot to receive a link to the portal from which you can enable the bridging. Open the link sent by the bot and follow the instructions.
|
||||
|
||||
Automatic login may not work. If it does not, reload the page and select the "Manual login" checkbox before starting. Manual login involves logging into your Google account normally and then manually getting the OAuth token from browser cookies with developer tools.
|
||||
|
||||
Once logged in, recent chats should show up as new conversations automatically. Other chats will get portals as you receive messages.
|
||||
|
||||
You can learn more about authentication from the bridge's [official documentation on Authentication](https://github.com/tulir/mautrix-hangouts/wiki/Authentication).
|
@ -0,0 +1,80 @@
|
||||
# Setting up Email2Matrix (optional)
|
||||
|
||||
The playbook can install and configure [email2matrix](https://github.com/devture/email2matrix) for you.
|
||||
|
||||
See the project's [documentation](https://github.com/devture/email2matrix/blob/master/docs/README.md) to learn what it does and why it might be useful to you.
|
||||
|
||||
|
||||
## Preparation
|
||||
|
||||
### Port availability
|
||||
|
||||
Ensure that port 25 is available on your Matrix server and open in your firewall.
|
||||
If you have `postfix` or some other email server software installed, you may need to manually remove it first (unless you need it, of course).
|
||||
|
||||
If you really need to run an email server on the Matrix machine for other purposes, it may be possible to run Email2Matrix on another port (with a configuration like `matrix_email2matrix_smtp_host_bind_port: "127.0.0.01:2525"`) and have your other email server relay messages there.
|
||||
For details about using Email2Matrix alongside [Postfix](http://www.postfix.org/), see [here](https://github.com/devture/email2matrix/blob/master/docs/setup_with_postfix.md).
|
||||
|
||||
### Creating a user
|
||||
|
||||
Before enabling Email2Matrix, you'd most likely wish to create a dedicated user (or more) that would be sending messages on the Matrix side.
|
||||
Refer to [Registering users](registering-users.md) for ways to do that. A regular (non-admin) user works best.
|
||||
|
||||
### Creating a shared room
|
||||
|
||||
After creating a sender user, you should create one or more Matrix rooms that you share with that user.
|
||||
It doesn't matter who creates and owns the rooms and who joins later (you or the sender user).
|
||||
|
||||
What matters is that both you and the sender user are part of the same room and that the sender user has enough privileges in the room to be able to send messages there.
|
||||
Inviting additional people to the room is okay too.
|
||||
|
||||
Take note of each room's room id (different clients show the room id in a different place).
|
||||
You'll need the room id when doing [Configuration](#configuration) below.
|
||||
|
||||
|
||||
### Obtaining an access token for the sender user
|
||||
|
||||
In order for the sender user created above to be able to send messages to the room, we'll need to obtain an access token for it.
|
||||
|
||||
To do this, you can execute a command like this:
|
||||
|
||||
```
|
||||
curl \
|
||||
--data '{"identifier": {"type": "m.id.user", "user": "email2matrix" }, "password": "MATRIX_PASSWORD_FOR_THE_USER", "type": "m.login.password", "device_id": "Email2Matrix", "initial_device_display_name": "Email2Matrix"}' \
|
||||
https://matrix.DOMAIN/_matrix/client/r0/login
|
||||
```
|
||||
|
||||
Take note of the `access_token` value. You'll need the access token when doing [Configuration](#configuration) below.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
After doing the preparation steps above, adjust your `inventory/host_vars/matrix.DOMAIN/vars.yml` configuration like this:
|
||||
|
||||
```yaml
|
||||
matrix_email2matrix_enabled: true
|
||||
|
||||
matrix_email2matrix_matrix_mappings:
|
||||
- MailboxName: "my-mailbox"
|
||||
MatrixRoomId: "!someRoom:DOMAIN"
|
||||
MatrixHomeserverUrl: "https://matrix.DOMAIN"
|
||||
MatrixUserId: "@email2matrix:DOMAIN"
|
||||
MatrixAccessToken: "ACCESS_TOKEN_GOES_HERE"
|
||||
IgnoreSubject: false
|
||||
IgnoreBody: false
|
||||
SkipMarkdown: false
|
||||
|
||||
- MailboxName: "my-mailbox2"
|
||||
MatrixRoomId: "!anotherRoom:DOMAIN"
|
||||
MatrixHomeserverUrl: "https://matrix.DOMAIN"
|
||||
MatrixUserId: "@email2matrix:DOMAIN"
|
||||
MatrixAccessToken: "ACCESS_TOKEN_GOES_HERE"
|
||||
IgnoreSubject: true
|
||||
IgnoreBody: false
|
||||
SkipMarkdown: true
|
||||
```
|
||||
|
||||
You can also set `MatrixHomeserverUrl` to `http://matrix-synapse:8008`, instead of the public `https://matrix.DOMAIN`.
|
||||
However, that's more likely to break in the future if you switch to another server implementation than Synapse.
|
||||
|
||||
Re-run the playbook (`--tags=setup-email2matrix,start`) and try sending an email to `my-mailbox@matrix.DOMAIN`.
|
@ -0,0 +1,25 @@
|
||||
# Configure Ngnix (optional, advanced)
|
||||
|
||||
By default, this playbook installs its own nginx webserver (in a Docker container) which listens on ports 80 and 443.
|
||||
If that's alright, you can skip this.
|
||||
|
||||
|
||||
## Using Ngnix status
|
||||
|
||||
This will serve a statuspage to the hosting machine only. Useful for monitoring software like [longview](https://www.linode.com/docs/platform/longview/longview-app-for-nginx/)
|
||||
|
||||
```yaml
|
||||
matrix_nginx_proxy_proxy_matrix_nginx_status_enabled: true
|
||||
```
|
||||
|
||||
This will serve the status page under the following addresses:
|
||||
- `http://matrix.DOMAIN/nginx_status` (using HTTP)
|
||||
- `https://matrix.DOMAIN/nginx_status` (using HTTPS)
|
||||
|
||||
By default, if ```matrix_nginx_proxy_nginx_status_enabled``` is enabled, access to the status page would be allowed from the local IP address of the server. If you wish to allow access from other IP addresses, you can provide them as a list:
|
||||
|
||||
```yaml
|
||||
matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses:
|
||||
- 8.8.8.8
|
||||
- 1.1.1.1
|
||||
```
|
@ -0,0 +1,196 @@
|
||||
# mautrix-hangouts is a Matrix <-> Hangouts bridge
|
||||
# See: https://github.com/tulir/mautrix-hangouts
|
||||
|
||||
matrix_mautrix_hangouts_enabled: true
|
||||
|
||||
# See: https://mau.dev/tulir/mautrix-hangouts/container_registry
|
||||
matrix_mautrix_hangouts_docker_image: "dock.mau.dev/tulir/mautrix-hangouts:latest"
|
||||
matrix_mautrix_hangouts_docker_image_force_pull: "{{ matrix_mautrix_hangouts_docker_image.endswith(':latest') }}"
|
||||
|
||||
matrix_mautrix_hangouts_base_path: "{{ matrix_base_data_path }}/mautrix-hangouts"
|
||||
matrix_mautrix_hangouts_config_path: "{{ matrix_mautrix_hangouts_base_path }}/config"
|
||||
matrix_mautrix_hangouts_data_path: "{{ matrix_mautrix_hangouts_base_path }}/data"
|
||||
|
||||
matrix_mautrix_hangouts_public_endpoint: '/mautrix-hangouts'
|
||||
|
||||
matrix_mautrix_hangouts_homeserver_address: 'http://matrix-synapse:8008'
|
||||
matrix_mautrix_hangouts_homeserver_domain: '{{ matrix_domain }}'
|
||||
matrix_mautrix_hangouts_appservice_address: 'http://matrix-mautrix-hangouts:8080'
|
||||
|
||||
# A list of extra arguments to pass to the container
|
||||
matrix_mautrix_hangouts_container_extra_arguments: []
|
||||
|
||||
# List of systemd services that matrix-mautrix-hangouts.service depends on.
|
||||
matrix_mautrix_hangouts_systemd_required_services_list: ['docker.service']
|
||||
|
||||
# List of systemd services that matrix-mautrix-hangouts.service wants
|
||||
matrix_mautrix_hangouts_systemd_wanted_services_list: []
|
||||
|
||||
matrix_mautrix_hangouts_appservice_token: ''
|
||||
matrix_mautrix_hangouts_homeserver_token: ''
|
||||
|
||||
# Default mxisd configuration template which covers the generic use case.
|
||||
# You can customize it by controlling the various variables inside it.
|
||||
#
|
||||
# For a more advanced customization, you can extend the default (see `matrix_mautrix_hangouts_configuration_extension_yaml`)
|
||||
# or completely replace this variable with your own template.
|
||||
matrix_mautrix_hangouts_configuration_yaml: |
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
# Homeserver details
|
||||
homeserver:
|
||||
# The address that this appservice can use to connect to the homeserver.
|
||||
address: {{ matrix_mautrix_hangouts_homeserver_address }}
|
||||
# The domain of the homeserver (for MXIDs, etc).
|
||||
domain: {{ matrix_mautrix_hangouts_homeserver_domain }}
|
||||
# Whether or not to verify the SSL certificate of the homeserver.
|
||||
# Only applies if address starts with https://
|
||||
verify_ssl: true
|
||||
|
||||
# Application service host/registration related details
|
||||
# Changing these values requires regeneration of the registration.
|
||||
appservice:
|
||||
# The address that the homeserver can use to connect to this appservice.
|
||||
address: {{ matrix_mautrix_hangouts_appservice_address }}
|
||||
|
||||
# The hostname and port where this appservice should listen.
|
||||
hostname: 0.0.0.0
|
||||
port: 8080
|
||||
# The maximum body size of appservice API requests (from the homeserver) in mebibytes
|
||||
# Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s
|
||||
max_body_size: 1
|
||||
|
||||
# The full URI to the database. SQLite and Postgres are fully supported.
|
||||
# Other DBMSes supported by SQLAlchemy may or may not work.
|
||||
# Format examples:
|
||||
# SQLite: sqlite:///filename.db
|
||||
# Postgres: postgres://username:password@hostname/dbname
|
||||
database: sqlite:////data/mautrix-hangouts.db
|
||||
|
||||
# The unique ID of this appservice.
|
||||
id: hangouts
|
||||
# Username of the appservice bot.
|
||||
bot_username: hangoutsbot
|
||||
# Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty
|
||||
# to leave display name/avatar as-is.
|
||||
bot_displayname: Hangouts bridge bot
|
||||
bot_avatar: mxc://maunium.net/FBXZnpfORkBEruORbikmleAy
|
||||
|
||||
# Authentication tokens for AS <-> HS communication.
|
||||
as_token: "{{ matrix_mautrix_hangouts_appservice_token }}"
|
||||
hs_token: "{{ matrix_mautrix_hangouts_homeserver_token }}"
|
||||
|
||||
# Bridge config
|
||||
bridge:
|
||||
# Localpart template of MXIDs for Hangouts users.
|
||||
# {userid} is replaced with the user ID of the Hangouts user.
|
||||
username_template: "hangouts_{userid}"
|
||||
# Displayname template for Hangouts users.
|
||||
# {displayname} is replaced with the display name of the Hangouts user
|
||||
# as defined below in displayname_preference.
|
||||
# Keys available for displayname_preference are also available here.
|
||||
displayname_template: '{full_name} (Hangouts)'
|
||||
# Available keys:
|
||||
# "name" (full name)
|
||||
# "first_name"
|
||||
# "last_name"
|
||||
# "nickname"
|
||||
# "own_nickname" (user-specific!)
|
||||
displayname_preference:
|
||||
- name
|
||||
|
||||
# The prefix for commands. Only required in non-management rooms.
|
||||
command_prefix: "!HO"
|
||||
|
||||
# Number of chats to sync (and create portals for) on startup/login.
|
||||
# Maximum 20, set 0 to disable automatic syncing.
|
||||
initial_chat_sync: 20
|
||||
# Whether or not the Hangouts users of logged in Matrix users should be
|
||||
# invited to private chats when the user sends a message from another client.
|
||||
invite_own_puppet_to_pm: false
|
||||
# Whether or not to use /sync to get presence, read receipts and typing notifications when using
|
||||
# your own Matrix account as the Matrix puppet for your Hangouts account.
|
||||
sync_with_custom_puppets: true
|
||||
|
||||
# Whether or not to bridge presence in both directions. Hangouts allows users not to broadcast
|
||||
# presence, but then it won't send other users' presence to the client.
|
||||
presence: true
|
||||
|
||||
# Public website and API configs
|
||||
web:
|
||||
# Auth server config
|
||||
auth:
|
||||
# Publicly accessible base URL for the login endpoints.
|
||||
# The prefix below is not implicitly added. This URL and all subpaths should be proxied
|
||||
# or otherwise pointed to the appservice's webserver to the path specified below (prefix).
|
||||
# This path should usually include a trailing slash.
|
||||
# Internal prefix in the appservice web server for the login endpoints.
|
||||
public: "{{ matrix_homeserver_url }}{{ matrix_mautrix_hangouts_public_endpoint }}/login"
|
||||
prefix: "{{ matrix_mautrix_hangouts_public_endpoint }}/login"
|
||||
|
||||
|
||||
# Permissions for using the bridge.
|
||||
# Permitted values:
|
||||
# user - Use the bridge with puppeting.
|
||||
# admin - Use and administrate the bridge.
|
||||
# Permitted keys:
|
||||
# * - All Matrix users
|
||||
# domain - All users on that homeserver
|
||||
# mxid - Specific user
|
||||
permissions:
|
||||
'{{ matrix_mautrix_hangouts_homeserver_domain }}': user
|
||||
|
||||
# Python logging configuration.
|
||||
#
|
||||
# See section 16.7.2 of the Python documentation for more info:
|
||||
# https://docs.python.org/3.6/library/logging.config.html#configuration-dictionary-schema
|
||||
logging:
|
||||
version: 1
|
||||
formatters:
|
||||
colored:
|
||||
(): mautrix_hangouts.util.ColorFormatter
|
||||
format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s"
|
||||
normal:
|
||||
format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s"
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
formatter: colored
|
||||
loggers:
|
||||
mau:
|
||||
level: DEBUG
|
||||
hangups:
|
||||
level: DEBUG
|
||||
aiohttp:
|
||||
level: INFO
|
||||
root:
|
||||
level: DEBUG
|
||||
handlers: [console]
|
||||
|
||||
matrix_mautrix_hangouts_configuration_extension_yaml: |
|
||||
# Your custom YAML configuration goes here.
|
||||
# This configuration extends the default starting configuration (`matrix_mautrix_hangouts_configuration_yaml`).
|
||||
#
|
||||
# You can override individual variables from the default configuration, or introduce new ones.
|
||||
#
|
||||
# If you need something more special, you can take full control by
|
||||
# completely redefining `matrix_mautrix_hangouts_configuration_yaml`.
|
||||
|
||||
matrix_mautrix_hangouts_configuration_extension: "{{ matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml if matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml is mapping else {} }}"
|
||||
|
||||
# Holds the final configuration (a combination of the default and its extension).
|
||||
# You most likely don't need to touch this variable. Instead, see `matrix_mautrix_hangouts_configuration_yaml`.
|
||||
matrix_mautrix_hangouts_configuration: "{{ matrix_mautrix_hangouts_configuration_yaml|from_yaml|combine(matrix_mautrix_hangouts_configuration_extension, recursive=True) }}"
|
||||
|
||||
matrix_mautrix_hangouts_registration_yaml: |
|
||||
id: hangouts
|
||||
as_token: "{{ matrix_mautrix_hangouts_appservice_token }}"
|
||||
hs_token: "{{ matrix_mautrix_hangouts_homeserver_token }}"
|
||||
namespaces:
|
||||
users:
|
||||
- exclusive: true
|
||||
regex: '^@hangouts_.+:{{ matrix_mautrix_hangouts_homeserver_domain|regex_escape }}$'
|
||||
url: {{ matrix_mautrix_hangouts_appservice_address }}
|
||||
sender_localpart: hangoutsbot
|
||||
rate_limited: false
|
||||
|
||||
matrix_mautrix_hangouts_registration: "{{ matrix_mautrix_hangouts_registration_yaml|from_yaml }}"
|
@ -0,0 +1,62 @@
|
||||
- set_fact:
|
||||
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-hangouts'] }}"
|
||||
when: matrix_mautrix_hangouts_enabled|bool
|
||||
|
||||
# If the matrix-synapse role is not used, these variables may not exist.
|
||||
- set_fact:
|
||||
matrix_synapse_container_extra_arguments: >
|
||||
{{ matrix_synapse_container_extra_arguments|default([]) }}
|
||||
+
|
||||
{{ ["--mount type=bind,src={{ matrix_mautrix_hangouts_config_path }}/registration.yaml,dst=/matrix-mautrix-hangouts-registration.yaml,ro"] }}
|
||||
|
||||
matrix_synapse_app_service_config_files: >
|
||||
{{ matrix_synapse_app_service_config_files|default([]) }}
|
||||
+
|
||||
{{ ["/matrix-mautrix-hangouts-registration.yaml"] }}
|
||||
when: matrix_mautrix_hangouts_enabled|bool
|
||||
|
||||
- block:
|
||||
- name: Fail if matrix-nginx-proxy role already executed
|
||||
fail:
|
||||
msg: >-
|
||||
Trying to append Mautrix Hangouts's reverse-proxying configuration to matrix-nginx-proxy,
|
||||
but it's pointless since the matrix-nginx-proxy role had already executed.
|
||||
To fix this, please change the order of roles in your plabook,
|
||||
so that the matrix-nginx-proxy role would run after the matrix-bridge-mautrix-hangouts role.
|
||||
when: matrix_nginx_proxy_role_executed|default(False)|bool
|
||||
|
||||
- name: Generate Mautrix Hangouts proxying configuration for matrix-nginx-proxy
|
||||
set_fact:
|
||||
matrix_mautrix_hangouts_matrix_nginx_proxy_configuration: |
|
||||
location {{ matrix_mautrix_hangouts_public_endpoint }} {
|
||||
{% if matrix_nginx_proxy_enabled|default(False) %}
|
||||
{# Use the embedded DNS resolver in Docker containers to discover the service #}
|
||||
resolver 127.0.0.11 valid=5s;
|
||||
set $backend "matrix-mautrix-hangouts:8080";
|
||||
proxy_pass http://$backend;
|
||||
{% else %}
|
||||
{# Generic configuration for use outside of our container setup #}
|
||||
proxy_pass http://127.0.0.1:9007;
|
||||
{% endif %}
|
||||
}
|
||||
- name: Register Mautrix Hangouts proxying configuration with matrix-nginx-proxy
|
||||
set_fact:
|
||||
matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
|
||||
{{
|
||||
matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([])
|
||||
+
|
||||
[matrix_mautrix_hangouts_matrix_nginx_proxy_configuration]
|
||||
}}
|
||||
tags:
|
||||
- always
|
||||
when: matrix_mautrix_hangouts_enabled|bool
|
||||
|
||||
- name: Warn about reverse-proxying if matrix-nginx-proxy not used
|
||||
debug:
|
||||
msg: >-
|
||||
NOTE: You've enabled the Mautrix Hangouts bridge but are not using the matrix-nginx-proxy
|
||||
reverse proxy.
|
||||
Please make sure that you're proxying the `{{ matrix_mautrix_hangouts_public_endpoint }}`
|
||||
URL endpoint to the matrix-mautrix-hangouts container.
|
||||
You can expose the container's port using the `matrix_mautrix_hangouts_container_http_host_bind_port` variable.
|
||||
when: "matrix_mautrix_hangouts_enabled|bool and matrix_nginx_proxy_enabled is not defined"
|
@ -0,0 +1,21 @@
|
||||
- import_tasks: "{{ role_path }}/tasks/init.yml"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-mautrix-hangouts
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/setup_install.yml"
|
||||
when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-mautrix-hangouts
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
|
||||
when: "run_setup|bool and not matrix_mautrix_hangouts_enabled|bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-mautrix-hangouts
|
@ -0,0 +1,73 @@
|
||||
---
|
||||
|
||||
# If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
|
||||
# We don't want to fail in such cases.
|
||||
- name: Fail if matrix-synapse role already executed
|
||||
fail:
|
||||
msg: >-
|
||||
The matrix-bridge-mautrix-hangouts role needs to execute before the matrix-synapse role.
|
||||
when: "matrix_synapse_role_executed|default(False)"
|
||||
|
||||
- name: Ensure Mautrix Hangouts image is pulled
|
||||
docker_image:
|
||||
name: "{{ matrix_mautrix_hangouts_docker_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_mautrix_hangouts_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_hangouts_docker_image_force_pull }}"
|
||||
|
||||
- name: Ensure Mautrix Hangouts paths exist
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
with_items:
|
||||
- "{{ matrix_mautrix_hangouts_base_path }}"
|
||||
- "{{ matrix_mautrix_hangouts_config_path }}"
|
||||
- "{{ matrix_mautrix_hangouts_data_path }}"
|
||||
|
||||
- name: Check if an old database file already exists
|
||||
stat:
|
||||
path: "{{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db"
|
||||
register: matrix_mautrix_hangouts_stat_database
|
||||
|
||||
- name: (Data relocation) Ensure matrix-mautrix-hangouts.service is stopped
|
||||
service:
|
||||
name: matrix-mautrix-hangouts
|
||||
state: stopped
|
||||
daemon_reload: yes
|
||||
failed_when: false
|
||||
when: "matrix_mautrix_hangouts_stat_database.stat.exists"
|
||||
|
||||
- name: (Data relocation) Move mautrix-hangouts database file to ./data directory
|
||||
command: "mv {{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db {{ matrix_mautrix_hangouts_data_path }}/mautrix-hangouts.db"
|
||||
when: "matrix_mautrix_hangouts_stat_database.stat.exists"
|
||||
|
||||
- name: Ensure mautrix-hangouts config.yaml installed
|
||||
copy:
|
||||
content: "{{ matrix_mautrix_hangouts_configuration|to_nice_yaml }}"
|
||||
dest: "{{ matrix_mautrix_hangouts_config_path }}/config.yaml"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
|
||||
- name: Ensure mautrix-hangouts registration.yaml installed
|
||||
copy:
|
||||
content: "{{ matrix_mautrix_hangouts_registration|to_nice_yaml }}"
|
||||
dest: "{{ matrix_mautrix_hangouts_config_path }}/registration.yaml"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
|
||||
- name: Ensure matrix-mautrix-hangouts.service installed
|
||||
template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-mautrix-hangouts.service.j2"
|
||||
dest: "/etc/systemd/system/matrix-mautrix-hangouts.service"
|
||||
mode: 0644
|
||||
register: matrix_mautrix_hangouts_systemd_service_result
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-mautrix-hangouts.service installation
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "matrix_mautrix_hangouts_systemd_service_result.changed"
|
@ -0,0 +1,24 @@
|
||||
---
|
||||
|
||||
- name: Check existence of matrix-mautrix-hangouts service
|
||||
stat:
|
||||
path: "/etc/systemd/system/matrix-mautrix-hangouts.service"
|
||||
register: matrix_mautrix_hangouts_service_stat
|
||||
|
||||
- name: Ensure matrix-mautrix-hangouts is stopped
|
||||
service:
|
||||
name: matrix-mautrix-hangouts
|
||||
state: stopped
|
||||
daemon_reload: yes
|
||||
when: "matrix_mautrix_hangouts_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure matrix-mautrix-hangouts.service doesn't exist
|
||||
file:
|
||||
path: "/etc/systemd/system/matrix-mautrix-hangouts.service"
|
||||
state: absent
|
||||
when: "matrix_mautrix_hangouts_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-mautrix-hangouts.service removal
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "matrix_mautrix_hangouts_service_stat.stat.exists"
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
|
||||
- name: Fail if required settings not defined
|
||||
fail:
|
||||
msg: >-
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "vars[item] == ''"
|
||||
with_items:
|
||||
- "matrix_mautrix_hangouts_public_endpoint"
|
||||
- "matrix_mautrix_hangouts_appservice_token"
|
||||
- "matrix_mautrix_hangouts_homeserver_token"
|
||||
- debug:
|
||||
msg:
|
||||
- '`matrix_mautrix_hangouts_homeserver_domain` == {{ matrix_mautrix_hangouts_homeserver_domain }}'
|
@ -0,0 +1,48 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
[Unit]
|
||||
Description=Matrix Mautrix Hangouts server
|
||||
{% for service in matrix_mautrix_hangouts_systemd_required_services_list %}
|
||||
Requires={{ service }}
|
||||
After={{ service }}
|
||||
{% endfor %}
|
||||
{% for service in matrix_mautrix_hangouts_systemd_wanted_services_list %}
|
||||
Wants={{ service }}
|
||||
{% endfor %}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStartPre=-/usr/bin/docker kill matrix-mautrix-hangouts
|
||||
ExecStartPre=-/usr/bin/docker rm matrix-mautrix-hangouts
|
||||
ExecStartPre=/usr/bin/docker run --rm --name matrix-mautrix-hangouts-db \
|
||||
--log-driver=none \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
--cap-drop=ALL \
|
||||
-v {{ matrix_mautrix_hangouts_config_path }}:/config:z \
|
||||
-v {{ matrix_mautrix_hangouts_data_path }}:/data:z \
|
||||
{{ matrix_mautrix_hangouts_docker_image }} \
|
||||
alembic -x config=/config/config.yaml upgrade head
|
||||
|
||||
# Intentional delay, so that the homeserver (we likely depend on) can manage to start.
|
||||
ExecStartPre=/bin/sleep 5
|
||||
|
||||
ExecStart=/usr/bin/docker run --rm --name matrix-mautrix-hangouts \
|
||||
--log-driver=none \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
--cap-drop=ALL \
|
||||
--network={{ matrix_docker_network }} \
|
||||
-v {{ matrix_mautrix_hangouts_config_path }}:/config:z \
|
||||
-v {{ matrix_mautrix_hangouts_data_path }}:/data:z \
|
||||
{% for arg in matrix_mautrix_hangouts_container_extra_arguments %}
|
||||
{{ arg }} \
|
||||
{% endfor %}
|
||||
{{ matrix_mautrix_hangouts_docker_image }} \
|
||||
python3 -m mautrix_hangouts -c /config/config.yaml
|
||||
|
||||
ExecStop=-/usr/bin/docker kill matrix-mautrix-hangouts
|
||||
ExecStop=-/usr/bin/docker rm matrix-mautrix-hangouts
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
SyslogIdentifier=matrix-mautrix-hangouts
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,43 @@
|
||||
matrix_email2matrix_enabled: true
|
||||
|
||||
matrix_email2matrix_base_path: "{{ matrix_base_data_path }}/email2matrix"
|
||||
matrix_email2matrix_config_dir_path: "{{ matrix_email2matrix_base_path }}/config"
|
||||
|
||||
matrix_email2matrix_docker_image: "devture/email2matrix:1.0.1"
|
||||
matrix_email2matrix_docker_image_force_pull: "{{ matrix_email2matrix_docker_image.endswith(':latest') }}"
|
||||
|
||||
# A list of extra arguments to pass to the container
|
||||
matrix_email2matrix_container_extra_arguments: []
|
||||
|
||||
# List of systemd services that matrix-corporal.service depends on
|
||||
matrix_email2matrix_systemd_required_services_list: ['docker.service']
|
||||
|
||||
# Controls where the matrix-email2matrix container exposes the SMTP (tcp/2525 in the container).
|
||||
#
|
||||
# Takes an "<ip>:<port>" or "<port>" value (e.g. "127.0.0.1:2525").
|
||||
#
|
||||
# By default, we listen on port 25 on all of the host's network interfaces.
|
||||
matrix_email2matrix_smtp_host_bind_port: "25"
|
||||
|
||||
matrix_email2matrix_smtp_hostname: "{{ matrix_server_fqn_matrix }}"
|
||||
|
||||
# A list of mailbox to Matrix mappings.
|
||||
#
|
||||
# Example:
|
||||
# matrix_email2matrix_matrix_mappings:
|
||||
# - MailboxName: "mailbox1"
|
||||
# MatrixRoomId: "!bpcwlxIUxVvvgXcbjy:example.com"
|
||||
# MatrixHomeserverUrl: "{{ matrix_homeserver_url }}"
|
||||
# MatrixUserId": "@email2matrix:{{ matrix_domain }}"
|
||||
# MatrixAccessToken": "TOKEN_HERE"
|
||||
# IgnoreSubject: false
|
||||
#
|
||||
# - MailboxName: "mailbox2"
|
||||
# MatrixRoomId: "!another:example.com"
|
||||
# MatrixHomeserverUrl: "{{ matrix_homeserver_url }}"
|
||||
# MatrixUserId": "@email2matrix:{{ matrix_domain }}"
|
||||
# MatrixAccessToken": "TOKEN_HERE"
|
||||
# IgnoreSubject: true
|
||||
matrix_email2matrix_matrix_mappings: []
|
||||
|
||||
matrix_email2matrix_misc_debug: false
|
@ -0,0 +1,3 @@
|
||||
- set_fact:
|
||||
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-email2matrix'] }}"
|
||||
when: matrix_email2matrix_enabled|bool
|
@ -0,0 +1,15 @@
|
||||
- import_tasks: "{{ role_path }}/tasks/init.yml"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
when: "run_setup|bool and matrix_email2matrix_enabled|bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-email2matrix
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/setup_email2matrix.yml"
|
||||
when: run_setup|bool
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-email2matrix
|
@ -0,0 +1,88 @@
|
||||
---
|
||||
|
||||
#
|
||||
# Tasks related to setting up Email2Matrix
|
||||
#
|
||||
|
||||
- name: Ensure Email2Matrix paths exist
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
with_items:
|
||||
- "{{ matrix_email2matrix_base_path }}"
|
||||
- "{{ matrix_email2matrix_config_dir_path }}"
|
||||
when: matrix_email2matrix_enabled|bool
|
||||
|
||||
- name: Ensure Email2Matrix configuration file created
|
||||
template:
|
||||
src: "{{ role_path }}/templates/config.json.j2"
|
||||
dest: "{{ matrix_email2matrix_config_dir_path }}/config.json"
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
mode: 0640
|
||||
when: matrix_email2matrix_enabled|bool
|
||||
|
||||
- name: Ensure Email2Matrix image is pulled
|
||||
docker_image:
|
||||
name: "{{ matrix_email2matrix_docker_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_email2matrix_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_email2matrix_docker_image_force_pull }}"
|
||||
when: matrix_email2matrix_enabled|bool
|
||||
|
||||
- name: Ensure matrix-email2matrix.service installed
|
||||
template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-email2matrix.service.j2"
|
||||
dest: "/etc/systemd/system/matrix-email2matrix.service"
|
||||
mode: 0644
|
||||
register: matrix_email2matrix_systemd_service_result
|
||||
when: matrix_email2matrix_enabled|bool
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-email2matrix.service installation
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "matrix_email2matrix_enabled|bool and matrix_email2matrix_systemd_service_result.changed"
|
||||
|
||||
#
|
||||
# Tasks related to getting rid of the Email2Matrix (if it was previously enabled)
|
||||
#
|
||||
|
||||
- name: Check existence of matrix-email2matrix service
|
||||
stat:
|
||||
path: "/etc/systemd/system/matrix-email2matrix.service"
|
||||
register: matrix_email2matrix_service_stat
|
||||
when: "not matrix_email2matrix_enabled|bool"
|
||||
|
||||
- name: Ensure matrix-email2matrix is stopped
|
||||
service:
|
||||
name: matrix-email2matrix
|
||||
state: stopped
|
||||
daemon_reload: yes
|
||||
register: stopping_result
|
||||
when: "not matrix_email2matrix_enabled|bool and matrix_email2matrix_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure matrix-email2matrix.service doesn't exist
|
||||
file:
|
||||
path: "/etc/systemd/system/matrix-email2matrix.service"
|
||||
state: absent
|
||||
when: "not matrix_email2matrix_enabled|bool and matrix_email2matrix_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-email2matrix.service removal
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "not matrix_email2matrix_enabled|bool and matrix_email2matrix_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure Email2Matrix data path doesn't exist
|
||||
file:
|
||||
path: "{{ matrix_email2matrix_base_path }}"
|
||||
state: absent
|
||||
when: "not matrix_email2matrix_enabled|bool"
|
||||
|
||||
- name: Ensure Email2Matrix Docker image doesn't exist
|
||||
docker_image:
|
||||
name: "{{ matrix_email2matrix_docker_image }}"
|
||||
state: absent
|
||||
when: "not matrix_email2matrix_enabled|bool"
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- name: Fail if no mappings
|
||||
fail:
|
||||
msg: >
|
||||
You need to define at least one mapping in `matrix_email2matrix_matrix_mappings` for enabling Email2Matrix.
|
||||
when: "matrix_email2matrix_matrix_mappings|length == 0"
|
@ -0,0 +1,14 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
{
|
||||
"Smtp": {
|
||||
"ListenInterface": "0.0.0.0:2525",
|
||||
"Hostname": {{ matrix_email2matrix_smtp_hostname|to_json }},
|
||||
"Workers": 10
|
||||
},
|
||||
"Matrix": {
|
||||
"Mappings": {{ matrix_email2matrix_matrix_mappings|to_nice_json }}
|
||||
},
|
||||
"Misc": {
|
||||
"Debug": {{ matrix_email2matrix_misc_debug|to_json }}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
[Unit]
|
||||
Description=Email2Matrix
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStartPre=-/usr/bin/docker kill matrix-email2matrix
|
||||
ExecStartPre=-/usr/bin/docker rm matrix-email2matrix
|
||||
|
||||
ExecStart=/usr/bin/docker run --rm --name matrix-email2matrix \
|
||||
--log-driver=none \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
--cap-drop=ALL \
|
||||
--read-only \
|
||||
--network={{ matrix_docker_network }} \
|
||||
-p {{ matrix_email2matrix_smtp_host_bind_port }}:2525 \
|
||||
--mount type=bind,src={{ matrix_email2matrix_config_dir_path }}/config.json,dst=/config.json,ro \
|
||||
{% for arg in matrix_email2matrix_container_extra_arguments %}
|
||||
{{ arg }} \
|
||||
{% endfor %}
|
||||
{{ matrix_email2matrix_docker_image }}
|
||||
|
||||
ExecStop=-/usr/bin/docker kill matrix-email2matrix
|
||||
ExecStop=-/usr/bin/docker rm matrix-email2matrix
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
SyslogIdentifier=matrix-email2matrix
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in new issue