Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.8 KiB

  1. ---
  2. - name: Ensure Dendrite paths exist
  3. ansible.builtin.file:
  4. path: "{{ item }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - "{{ matrix_dendrite_config_dir_path }}"
  11. - "{{ matrix_dendrite_bin_path }}"
  12. - "{{ matrix_dendrite_ext_path }}"
  13. - "{{ matrix_dendrite_nats_storage_path }}"
  14. # This will throw a Permission Denied error if already mounted using fuse
  15. - name: Check Dendrite media store path
  16. ansible.builtin.stat:
  17. path: "{{ matrix_dendrite_media_store_path }}"
  18. register: local_path_media_store_stat
  19. ignore_errors: true
  20. # This is separate and conditional, to ensure we don't execute it
  21. # if the path already exists or we failed to check, because it's mounted using fuse.
  22. - name: Ensure Dendrite media store path exists
  23. ansible.builtin.file:
  24. path: "{{ matrix_dendrite_media_store_path }}"
  25. state: directory
  26. mode: 0750
  27. owner: "{{ matrix_user_username }}"
  28. group: "{{ matrix_user_groupname }}"
  29. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  30. - name: Ensure Dendrite Docker image is pulled
  31. community.docker.docker_image:
  32. name: "{{ matrix_dendrite_docker_image }}"
  33. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  34. force_source: "{{ matrix_dendrite_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  35. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dendrite_docker_image_force_pull }}"
  36. register: result
  37. retries: "{{ devture_playbook_help_container_retries_count }}"
  38. delay: "{{ devture_playbook_help_container_retries_delay }}"
  39. until: result is not failed
  40. - name: Check if a Dendrite signing key exists
  41. ansible.builtin.stat:
  42. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  43. register: matrix_dendrite_signing_key_stat
  44. # We do this so that the signing key would get generated.
  45. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  46. # a very recent version, which is not available for a lot of people yet.
  47. - name: Generate Dendrite signing key
  48. ansible.builtin.command: |
  49. docker run
  50. --rm
  51. --name=matrix-dendrite-config
  52. --entrypoint=generate-keys
  53. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  54. {{ matrix_dendrite_docker_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  55. generate
  56. when: "not matrix_dendrite_signing_key_stat.stat.exists"
  57. - name: Ensure Dendrite server key exists
  58. ansible.builtin.file:
  59. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  60. mode: 0644
  61. owner: "{{ matrix_user_username }}"
  62. group: "{{ matrix_user_groupname }}"
  63. - name: Ensure Dendrite configuration installed
  64. ansible.builtin.copy:
  65. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  66. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  67. mode: 0644
  68. owner: "{{ matrix_user_username }}"
  69. group: "{{ matrix_user_groupname }}"
  70. - name: Ensure Dendrite container network is created
  71. community.general.docker_network:
  72. name: "{{ matrix_dendrite_container_network }}"
  73. driver: bridge
  74. - name: Ensure matrix-dendrite.service installed
  75. ansible.builtin.template:
  76. src: "{{ role_path }}/templates/dendrite/systemd/matrix-dendrite.service.j2"
  77. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  78. mode: 0644
  79. - name: Ensure Dendrite scripts created
  80. ansible.builtin.template:
  81. src: "{{ role_path }}/templates/dendrite/bin/{{ item }}.j2"
  82. dest: "{{ matrix_dendrite_bin_path }}/{{ item }}"
  83. mode: 0750
  84. with_items:
  85. - create-account