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.
 
 

114 lines
4.7 KiB

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