2017-07-31 22:07:30 +02:00
|
|
|
---
|
|
|
|
|
2017-09-07 11:12:31 +02:00
|
|
|
- name: Ensure Matrix Synapse paths exists
|
2017-07-31 22:07:30 +02:00
|
|
|
file:
|
2017-09-07 11:12:31 +02:00
|
|
|
path: "{{ item }}"
|
2017-07-31 22:07:30 +02:00
|
|
|
state: directory
|
|
|
|
mode: 0750
|
|
|
|
owner: "{{ matrix_user_username }}"
|
|
|
|
group: "{{ matrix_user_username }}"
|
2017-09-07 11:12:31 +02:00
|
|
|
with_items:
|
|
|
|
- "{{ matrix_synapse_config_dir_path }}"
|
|
|
|
- "{{ matrix_synapse_run_path }}"
|
2018-02-20 21:36:08 +02:00
|
|
|
- "{{ matrix_synapse_storage_path }}"
|
2017-09-07 17:26:41 +02:00
|
|
|
# We handle matrix_synapse_media_store_path below, not here,
|
|
|
|
# because if it's using S3fs and it's already mounted (from before),
|
|
|
|
# trying to chown/chmod it here will cause trouble.
|
|
|
|
|
2018-02-20 21:36:08 +02:00
|
|
|
# This will throw a Permission Denied error if already mounted using fuse
|
2017-09-07 17:26:41 +02:00
|
|
|
- name: Check Matrix Synapse media store path
|
|
|
|
stat: path="{{ matrix_synapse_media_store_path }}"
|
|
|
|
register: local_path_media_store_stat
|
2018-02-20 21:36:08 +02:00
|
|
|
ignore_errors: yes
|
2017-09-07 17:26:41 +02:00
|
|
|
|
|
|
|
# This is separate and conditional, to ensure we don't execute it
|
2018-02-20 21:36:08 +02:00
|
|
|
# if the path already exists or we failed to check, because it's mounted using fuse.
|
2017-09-07 17:26:41 +02:00
|
|
|
- name: Ensure Matrix media store path exists
|
|
|
|
file:
|
|
|
|
path: "{{ matrix_synapse_media_store_path }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0750
|
|
|
|
owner: "{{ matrix_user_username }}"
|
|
|
|
group: "{{ matrix_user_username }}"
|
2018-02-20 21:36:08 +02:00
|
|
|
when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- name: Ensure Matrix Docker image is pulled
|
|
|
|
docker_image:
|
|
|
|
name: "{{ docker_matrix_image }}"
|
|
|
|
|
2017-08-12 10:06:57 +02:00
|
|
|
- name: Check if a Matrix Synapse configuration exists
|
|
|
|
stat:
|
2017-09-07 11:12:31 +02:00
|
|
|
path: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-08-12 10:06:57 +02:00
|
|
|
register: matrix_synapse_config_stat
|
|
|
|
|
2017-07-31 22:07:30 +02:00
|
|
|
- name: Generate initial Matrix config
|
|
|
|
docker_container:
|
|
|
|
name: matrix-config
|
|
|
|
image: "{{ docker_matrix_image }}"
|
|
|
|
detach: no
|
|
|
|
cleanup: yes
|
|
|
|
command: generate
|
|
|
|
env:
|
2018-05-25 20:58:53 +02:00
|
|
|
SYNAPSE_CONFIG_PATH: "/data/homeserver.yaml"
|
|
|
|
SYNAPSE_SERVER_NAME: "{{ hostname_matrix }}"
|
|
|
|
SYNAPSE_REPORT_STATS: "no"
|
2017-07-31 22:07:30 +02:00
|
|
|
user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
|
|
|
|
volumes:
|
2017-09-07 11:12:31 +02:00
|
|
|
- "{{ matrix_synapse_config_dir_path }}:/data"
|
2017-08-12 10:06:57 +02:00
|
|
|
when: "not matrix_synapse_config_stat.stat.exists"
|
2017-07-31 22:07:30 +02:00
|
|
|
|
2017-09-07 11:12:31 +02:00
|
|
|
- name: Augment Matrix log config
|
|
|
|
lineinfile: "dest={{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.log.config"
|
2017-08-12 09:36:34 +02:00
|
|
|
args:
|
2017-09-07 11:12:31 +02:00
|
|
|
regexp: "{{ item.regexp }}"
|
|
|
|
line: '{{ item.line }}'
|
2018-05-25 12:15:17 +02:00
|
|
|
backrefs: '{{ item.backrefs }}'
|
2017-09-07 11:12:31 +02:00
|
|
|
with_items:
|
2018-05-25 12:15:17 +02:00
|
|
|
- {"regexp": '^(\s+)filename:', "line": '\1filename: /matrix-run/homeserver.log', backrefs: yes}
|
|
|
|
- {"regexp": '^(\s+)maxBytes:', "line": '\1maxBytes: {{ matrix_max_log_file_size_mb * 1024 * 1024 }}', backrefs: yes}
|
|
|
|
- {"regexp": '^(\s+)backupCount:', "line": '\1backupCount: {{ matrix_max_log_files_count }}', backrefs: yes}
|
2017-08-12 09:36:34 +02:00
|
|
|
|
2017-09-07 11:12:31 +02:00
|
|
|
- name: Augment Matrix config
|
|
|
|
lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-08-12 09:36:34 +02:00
|
|
|
args:
|
2017-09-07 11:12:31 +02:00
|
|
|
regexp: "{{ item.regexp }}"
|
|
|
|
line: '{{ item.line }}'
|
|
|
|
with_items:
|
|
|
|
- {"regexp": "^log_file:", "line": 'log_file: "/matrix-run/homeserver.log"'}
|
2018-05-25 20:58:53 +02:00
|
|
|
- {"regexp": "^uploads_path:", "line": 'uploads_path: "/matrix-run/uploads"'}
|
2017-09-07 11:12:31 +02:00
|
|
|
- {"regexp": "^server_name:", "line": 'server_name: "{{ hostname_identity }}"'}
|
|
|
|
- {"regexp": "^turn_allow_guests:", "line": 'turn_allow_guests: False'}
|
|
|
|
- {"regexp": "^url_preview_enabled:", "line": 'url_preview_enabled: True'}
|
|
|
|
- {"regexp": "^max_upload_size:", "line": 'max_upload_size: "{{ matrix_max_upload_size_mb }}M"'}
|
2018-02-20 21:36:08 +02:00
|
|
|
- {"regexp": "^media_store_path:", "line": 'media_store_path: "/matrix-storage/media-store"'}
|
2017-08-12 09:36:34 +02:00
|
|
|
|
2017-10-24 08:29:19 +02:00
|
|
|
- name: Augment Matrix config (configure Macaroon secret)
|
|
|
|
lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
|
|
|
args:
|
|
|
|
regexp: "{{ item.regexp }}"
|
|
|
|
line: '{{ item.line }}'
|
|
|
|
with_items:
|
|
|
|
- {"regexp": "^macaroon_secret_key:", "line": 'macaroon_secret_key: "{{ matrix_synapse_macaroon_secret_key }}"'}
|
|
|
|
when: "matrix_synapse_macaroon_secret_key is not none"
|
|
|
|
|
2017-08-12 09:36:34 +02:00
|
|
|
- name: Augment Matrix config (specify URL previews blacklist)
|
2017-09-07 11:12:31 +02:00
|
|
|
lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-08-12 09:36:34 +02:00
|
|
|
args:
|
|
|
|
regexp: "^url_preview_ip_range_blacklist:"
|
|
|
|
line: 'url_preview_ip_range_blacklist: ["127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10", "169.254.0.0/16"]'
|
|
|
|
insertafter: '^# url_preview_ip_range_blacklist:$'
|
|
|
|
|
2017-08-12 17:32:24 +02:00
|
|
|
# We only wish to do this for the 8008 port and not for the 8448 port
|
|
|
|
# (2nd instance of `x_forwarded` found in the config)
|
|
|
|
- name: Augment Matrix config (mark 8008 plain traffic as forwarded)
|
2017-09-07 11:12:31 +02:00
|
|
|
replace: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-08-12 17:32:24 +02:00
|
|
|
args:
|
|
|
|
regexp: "8008((?:.|\n)*)x_forwarded(.*)"
|
|
|
|
replace: '8008\g<1>x_forwarded: true'
|
|
|
|
|
2017-07-31 22:07:30 +02:00
|
|
|
- name: Augment Matrix config (change database from SQLite to Postgres)
|
|
|
|
lineinfile:
|
2017-09-07 11:12:31 +02:00
|
|
|
dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-07-31 22:07:30 +02:00
|
|
|
regexp: '(.*)name: "sqlite3"'
|
|
|
|
line: '\1name: "psycopg2"'
|
|
|
|
backrefs: yes
|
|
|
|
|
2017-09-08 15:53:24 +02:00
|
|
|
- name: Augment Matrix config (set the Postgres connection parameters)
|
|
|
|
replace:
|
2017-09-07 11:12:31 +02:00
|
|
|
dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-09-08 15:53:24 +02:00
|
|
|
regexp: '(.*)name: "psycopg2"((?:.|\n)*?)\n\n'
|
|
|
|
replace: '\1name: "psycopg2"\n\1args:\n\1\1user: "{{ matrix_postgres_connection_username }}"\n\1\1password: "{{ matrix_postgres_connection_password }}"\n\1\1database: "{{ matrix_postgres_db_name }}"\n\1\1host: "{{ matrix_postgres_connection_hostname }}"\n\1\1cp_min: 5\n\1\1cp_max: 10\n\n'
|
2017-07-31 22:07:30 +02:00
|
|
|
|
2018-05-25 20:58:53 +02:00
|
|
|
- name: Augment Matrix config (configure TURN)
|
|
|
|
lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
|
2017-08-06 17:26:06 +02:00
|
|
|
args:
|
2018-05-25 20:58:53 +02:00
|
|
|
regexp: "{{ item.regexp }}"
|
|
|
|
line: '{{ item.line }}'
|
2017-08-06 17:26:06 +02:00
|
|
|
with_items:
|
2018-05-25 20:58:53 +02:00
|
|
|
- {"regexp": "^turn_uris:", "line": 'turn_uris: ["turn:{{ hostname_matrix }}:3478?transport=udp", "turn:{{ hostname_matrix }}:3478?transport=tcp"]'}
|
|
|
|
- {"regexp": "^turn_shared_secret:", "line": 'turn_shared_secret: "{{ matrix_coturn_turn_static_auth_secret }}"'}
|
2017-08-06 17:26:06 +02:00
|
|
|
|
2017-07-31 22:07:30 +02:00
|
|
|
- name: Allow access to Matrix ports in firewalld
|
|
|
|
firewalld:
|
2017-08-06 17:26:06 +02:00
|
|
|
port: "{{ item }}"
|
2017-07-31 22:07:30 +02:00
|
|
|
state: enabled
|
|
|
|
immediate: yes
|
|
|
|
permanent: yes
|
|
|
|
with_items:
|
2017-08-06 17:26:06 +02:00
|
|
|
- '8448/tcp' # Matrix federation
|
2017-09-11 22:24:05 +02:00
|
|
|
when: ansible_os_family == 'RedHat'
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- name: Ensure matrix-synapse.service installed
|
|
|
|
template:
|
|
|
|
src: "{{ role_path }}/templates/systemd/matrix-synapse.service.j2"
|
|
|
|
dest: "/etc/systemd/system/matrix-synapse.service"
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure matrix-synapse-register-user script created
|
|
|
|
template:
|
|
|
|
src: "{{ role_path }}/templates/usr-local-bin/matrix-synapse-register-user.j2"
|
|
|
|
dest: "/usr/local/bin/matrix-synapse-register-user"
|
|
|
|
mode: 0750
|