2017-07-31 22:07:30 +02:00
---
2019-01-01 15:37:57 +02:00
# Pre-checks
2017-07-31 22:07:30 +02:00
- name : Fail if playbook called incorrectly
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-01-08 00:35:35 +02:00
msg : "The `server_path_media_store` variable needs to be provided to this playbook, via --extra-vars"
2019-01-01 15:37:57 +02:00
when : "server_path_media_store is not defined or server_path_media_store.startswith('<')"
- name : Fail if media store is on Amazon S3
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-01-08 00:35:35 +02:00
msg : "Your media store is on Amazon S3. Due to technical limitations, restoring is not supported."
2022-07-18 10:22:05 +02:00
when : matrix_s3_media_store_enabled | bool
2017-07-31 22:07:30 +02:00
- name : Check if the provided media store directory exists
2022-07-18 10:22:05 +02:00
ansible.builtin.stat :
2019-01-08 00:35:35 +02:00
path : "{{ server_path_media_store }}"
2019-01-01 15:37:57 +02:00
register : server_path_media_store_stat
2017-07-31 22:07:30 +02:00
2019-01-01 15:37:57 +02:00
- name : Fail if provided media store directory doesn't exist on the server
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-01-08 00:35:35 +02:00
msg : "{{ server_path_media_store }} cannot be found on the server"
2019-01-01 15:37:57 +02:00
when : "not server_path_media_store_stat.stat.exists or not server_path_media_store_stat.stat.isdir"
2017-07-31 22:07:30 +02:00
2017-09-07 11:12:31 +02:00
- name : Check if media store contains local_content
2022-07-18 10:22:05 +02:00
ansible.builtin.stat :
2019-01-08 00:35:35 +02:00
path : "{{ server_path_media_store }}/local_content"
2019-01-01 15:37:57 +02:00
register : server_path_media_store_local_content_stat
2017-09-07 11:12:31 +02:00
- name : Check if media store contains remote_content
2022-07-18 10:22:05 +02:00
ansible.builtin.stat :
2019-01-08 00:35:35 +02:00
path : "{{ server_path_media_store }}/remote_content"
2019-01-01 15:37:57 +02:00
register : server_path_media_store_remote_content_stat
2017-09-07 11:12:31 +02:00
2017-09-07 11:23:22 +02:00
- name : Fail if media store directory doesn't look okay (lacking remote and local content)
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-01-08 00:35:35 +02:00
msg : "{{ server_path_media_store }} contains neither local_content nor remote_content directories. It's most likely a mistake and is not a media store directory."
2019-01-01 15:37:57 +02:00
when : "not server_path_media_store_local_content_stat.stat.exists and not server_path_media_store_remote_content_stat.stat.exists"
# Actual import work
2017-09-07 11:12:31 +02:00
2017-07-31 22:07:30 +02:00
- name : Ensure matrix-synapse is stopped
2022-07-18 09:39:08 +02:00
ansible.builtin.service :
2019-01-08 00:35:35 +02:00
name : matrix-synapse
state : stopped
2022-02-05 22:32:54 +02:00
enabled : false
daemon_reload : true
2017-07-31 22:07:30 +02:00
register : stopping_result
2019-01-01 15:37:57 +02:00
# This can only work with local files, not if the media store is on Amazon S3,
# as it won't be accessible in such a case.
- name : Ensure provided media store directory is synchronized
2022-11-01 07:05:26 +02:00
ansible.posix.synchronize :
2019-01-01 15:37:57 +02:00
src : "{{ server_path_media_store }}/"
2017-09-07 11:12:31 +02:00
dest : "{{ matrix_synapse_media_store_path }}"
2022-02-05 22:32:54 +02:00
delete : true
2017-09-07 11:27:32 +02:00
# It's wasteful to preserve owner/group now. We chown below anyway.
2022-02-05 22:32:54 +02:00
owner : false
2022-08-24 16:08:53 +02:00
group : false
2022-02-05 22:32:54 +02:00
times : true
2019-01-01 15:37:57 +02:00
delegate_to : "{{ inventory_hostname }}"
2017-07-31 22:07:30 +02:00
2018-02-20 21:36:08 +02:00
# This is for the generic case and fails in other cases (remote file systems),
# because in such cases the base path (matrix_synapse_media_store_path) is a mount point.
2017-09-07 17:26:41 +02:00
- name : Ensure media store permissions are correct (generic case)
2022-07-18 09:39:08 +02:00
ansible.builtin.file :
2017-09-07 11:23:22 +02:00
path : "{{ matrix_synapse_media_store_path }}"
owner : "{{ matrix_user_username }}"
2020-05-01 19:59:32 +02:00
group : "{{ matrix_user_groupname }}"
2022-02-05 22:32:54 +02:00
recurse : true
2022-07-18 10:22:05 +02:00
when : "not matrix_s3_media_store_enabled | bool"
2017-09-07 17:26:41 +02:00
2018-02-20 21:36:08 +02:00
# We don't chown for Goofys, because due to the way it's mounted,
# all files become owned by whoever needs to own them.
2017-09-07 11:23:22 +02:00
2019-04-23 09:20:56 +02:00
- name : Ensure Synapse is started (if it previously was)
2022-07-18 09:39:08 +02:00
ansible.builtin.service :
2019-01-08 00:35:35 +02:00
name : "{{ item }}"
state : started
2022-02-05 22:32:54 +02:00
daemon_reload : true
2019-05-21 17:25:59 +02:00
when : "stopping_result.changed"
2017-07-31 22:07:30 +02:00
with_items :
- matrix-synapse