Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

125 строки
5.3 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. # We do this so that the signing key would get generated.
  47. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  48. # a very recent version, which is not available for a lot of people yet.
  49. - name: Generate Dendrite signing key
  50. ansible.builtin.command:
  51. cmd: |
  52. docker run
  53. --rm
  54. --name=matrix-dendrite-config
  55. --entrypoint=generate-keys
  56. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  57. {{ matrix_dendrite_docker_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  58. generate
  59. creates: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  60. - name: Ensure Dendrite server key exists
  61. ansible.builtin.file:
  62. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  63. mode: 0644
  64. owner: "{{ matrix_user_username }}"
  65. group: "{{ matrix_user_groupname }}"
  66. - name: Ensure Dendrite configuration installed
  67. ansible.builtin.copy:
  68. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  69. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  70. mode: 0644
  71. owner: "{{ matrix_user_username }}"
  72. group: "{{ matrix_user_groupname }}"
  73. - when: "matrix_dendrite_container_image_self_build | bool"
  74. block:
  75. - name: Ensure Dendrite repository is present on self-build
  76. ansible.builtin.git:
  77. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  78. dest: "{{ matrix_dendrite_docker_src_files_path }}"
  79. version: "{{ matrix_dendrite_docker_image.split(':')[1] }}"
  80. force: "yes"
  81. become: true
  82. become_user: "{{ matrix_user_username }}"
  83. register: matrix_dendrite_git_pull_results
  84. - name: Check if Dendrite Docker image exists
  85. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_docker_image }}'"
  86. register: matrix_dendrite_docker_image_check_result
  87. changed_when: false
  88. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  89. # because the latter does not support BuildKit.
  90. # See: https://github.com/ansible-collections/community.general/issues/514
  91. - name: Ensure Dendrite Docker image is built
  92. ansible.builtin.command:
  93. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_docker_image }} {{ matrix_dendrite_docker_src_files_path }}"
  94. environment:
  95. DOCKER_BUILDKIT: 1
  96. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_docker_image_check_result.stdout == ''"
  97. - name: Ensure Dendrite container network is created
  98. community.general.docker_network:
  99. name: "{{ matrix_dendrite_container_network }}"
  100. driver: bridge
  101. - name: Ensure matrix-dendrite.service installed
  102. ansible.builtin.template:
  103. src: "{{ role_path }}/templates/dendrite/systemd/matrix-dendrite.service.j2"
  104. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  105. mode: 0644
  106. - name: Ensure Dendrite scripts created
  107. ansible.builtin.template:
  108. src: "{{ role_path }}/templates/dendrite/bin/{{ item }}.j2"
  109. dest: "{{ matrix_dendrite_bin_path }}/{{ item }}"
  110. mode: 0750
  111. with_items:
  112. - create-account