matrix-docker-ansible-deploy/roles/matrix-server/tasks/import_media_store.yml

83 lines
3.3 KiB
YAML

---
- name: Fail if playbook called incorrectly
fail: msg="The `local_path_media_store` variable needs to be provided to this playbook, via --extra-vars"
when: "local_path_media_store is not defined or local_path_media_store.startswith('<')"
- name: Check if the provided media store directory exists
stat: path="{{ local_path_media_store }}"
delegate_to: 127.0.0.1
become: false
register: local_path_media_store_stat
- name: Fail if provided media store directory doesn't exist on the local machine
fail: msg="{{ local_path_media_store }} cannot be found on the local machine"
when: "not local_path_media_store_stat.stat.exists or not local_path_media_store_stat.stat.isdir"
- name: Check if media store contains local_content
stat: path="{{ local_path_media_store }}/local_content"
delegate_to: 127.0.0.1
become: false
register: local_path_media_store_local_content_stat
- name: Check if media store contains remote_content
stat: path="{{ local_path_media_store }}/remote_content"
delegate_to: 127.0.0.1
become: false
register: local_path_media_store_remote_content_stat
- name: Fail if media store directory doesn't look okay (lacking remote and local content)
fail: msg="{{ local_path_media_store }} contains neither local_content nor remote_content. It's most likely a mistake and is not a media store directory."
when: "not local_path_media_store_local_content_stat.stat.exists and not local_path_media_store_remote_content_stat.stat.exists"
- name: Ensure matrix-synapse is stopped
service: name=matrix-synapse state=stopped daemon_reload=yes
register: stopping_result
- name: Ensure provided media store directory is copied to the server
synchronize:
src: "{{ local_path_media_store }}/"
dest: "{{ matrix_synapse_media_store_path }}"
delete: yes
# It's wasteful to preserve owner/group now. We chown below anyway.
owner: no
group: no
# The default of times=yes does not work when s3fs is used.
times: "{{ False if matrix_s3_media_store_enabled else True }}"
perms: "{{ False if matrix_s3_media_store_enabled else True }}"
# This is for the generic case and fails for remote file systems,
# because the base path (matrix_synapse_media_store_path) is a mount point.
- name: Ensure media store permissions are correct (generic case)
file:
path: "{{ matrix_synapse_media_store_path }}"
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_username }}"
recurse: yes
when: "not matrix_s3_media_store_enabled"
- name: Determine media store subdirectories
find: paths="{{ local_path_media_store }}" file_type=directory
delegate_to: 127.0.0.1
become: false
register: media_store_directories_result
when: "matrix_s3_media_store_enabled"
# This is the s3fs special case. We chown the subdirectories one by one,
# without touching the base directory.
- name: Ensure media store permissions are correct (s3fs)
file:
path: "{{ matrix_synapse_media_store_path }}/{{ item.path|basename }}"
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_username }}"
recurse: yes
with_items: "{{ media_store_directories_result.files }}"
when: "matrix_s3_media_store_enabled"
- name: Ensure Matrix Synapse is started (if it previously was)
service: name="{{ item }}" state=started daemon_reload=yes
when: stopping_result.changed
with_items:
- matrix-synapse
- matrix-nginx-proxy