Matrix Docker Ansible eploy
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 

173 рядки
7.1 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Arthur Brugière
  3. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  4. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  5. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  6. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  7. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  8. # SPDX-FileCopyrightText: 2023 Luke Moch
  9. # SPDX-FileCopyrightText: 2024 David Mehren
  10. #
  11. # SPDX-License-Identifier: AGPL-3.0-or-later
  12. ---
  13. - ansible.builtin.include_role:
  14. name: custom/matrix-base
  15. tasks_from: ensure_openssl_installed
  16. - name: Ensure hookshot paths exist
  17. ansible.builtin.file:
  18. path: "{{ item.path }}"
  19. state: directory
  20. mode: '0750'
  21. owner: "{{ matrix_user_name }}"
  22. group: "{{ matrix_group_name }}"
  23. with_items:
  24. - {path: "{{ matrix_hookshot_base_path }}", when: true}
  25. - {path: "{{ matrix_hookshot_container_src_files_path }}", when: "{{ matrix_hookshot_container_image_self_build }}"}
  26. when: item.when | bool
  27. - name: Ensure hookshot image is pulled
  28. community.docker.docker_image_pull:
  29. name: "{{ matrix_hookshot_container_image }}"
  30. pull: always
  31. when: not matrix_hookshot_container_image_self_build
  32. register: matrix_hookshot_container_image_pull_result
  33. retries: "{{ devture_playbook_help_container_retries_count }}"
  34. delay: "{{ devture_playbook_help_container_retries_delay }}"
  35. until: matrix_hookshot_container_image_pull_result is not failed
  36. - name: Ensure hookshot repository is present on self-build
  37. ansible.builtin.git:
  38. repo: "{{ matrix_hookshot_container_image_self_build_repo }}"
  39. dest: "{{ matrix_hookshot_container_src_files_path }}"
  40. version: "{{ matrix_hookshot_container_image_self_build_branch }}"
  41. force: "yes"
  42. become: true
  43. become_user: "{{ matrix_user_name }}"
  44. register: matrix_hookshot_git_pull_results
  45. when: "matrix_hookshot_container_image_self_build | bool"
  46. - name: Ensure hookshot Docker image is built
  47. community.docker.docker_image_build:
  48. name: "{{ matrix_hookshot_container_image }}"
  49. dockerfile: Dockerfile
  50. path: "{{ matrix_hookshot_container_src_files_path }}"
  51. pull: true
  52. rebuild: "{{ 'always' if matrix_hookshot_git_pull_results.changed | bool else 'never' }}"
  53. when: "matrix_hookshot_container_image_self_build | bool"
  54. register: matrix_hookshot_container_image_build_result
  55. - name: Check if hookshot passkey exists
  56. ansible.builtin.stat:
  57. path: "{{ matrix_hookshot_base_path }}/passkey.pem"
  58. register: hookshot_passkey_file
  59. - name: Generate hookshot passkey if it doesn't exist
  60. ansible.builtin.shell:
  61. cmd: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  62. creates: "{{ matrix_hookshot_base_path }}/passkey.pem"
  63. become: true
  64. become_user: "{{ matrix_user_name }}"
  65. when: "not hookshot_passkey_file.stat.exists"
  66. # We intentionally reconcile the passkey ownership/mode after generation,
  67. # because some setups can end up creating host-side files as the SSH user
  68. # instead of `matrix` when `become_user` is effectively not honored.
  69. #
  70. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5033
  71. - name: Ensure hookshot passkey has correct ownership and mode
  72. ansible.builtin.file:
  73. path: "{{ matrix_hookshot_base_path }}/passkey.pem"
  74. state: file
  75. mode: '0600'
  76. owner: "{{ matrix_user_name }}"
  77. group: "{{ matrix_group_name }}"
  78. register: matrix_hookshot_passkey_result
  79. - name: Ensure hookshot config.yml installed if provided
  80. ansible.builtin.copy:
  81. content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  82. dest: "{{ matrix_hookshot_base_path }}/config.yml"
  83. mode: '0644'
  84. owner: "{{ matrix_user_name }}"
  85. group: "{{ matrix_group_name }}"
  86. register: matrix_hookshot_config_result
  87. - name: Validate hookshot config.yml
  88. ansible.builtin.command:
  89. cmd: |
  90. {{ devture_systemd_docker_base_host_command_docker }} run
  91. --rm
  92. --name={{ matrix_hookshot_container_url }}-validate
  93. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  94. --cap-drop=ALL
  95. --mount type=bind,src={{ matrix_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  96. {{ matrix_hookshot_container_image }} node config/Config.js /config.yml
  97. register: hookshot_config_validation_result
  98. changed_when: false
  99. - name: Fail if hookshot config.yml invalid
  100. ansible.builtin.fail:
  101. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  102. when: "hookshot_config_validation_result.rc > 0"
  103. - name: Ensure hookshot registration.yml installed if provided
  104. ansible.builtin.copy:
  105. content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  106. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  107. mode: '0644'
  108. owner: "{{ matrix_user_name }}"
  109. group: "{{ matrix_group_name }}"
  110. register: matrix_hookshot_registration_result
  111. - name: Ensure hookshot github private key file installed if github is enabled
  112. ansible.builtin.copy:
  113. content: "{{ matrix_hookshot_github_private_key }}"
  114. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  115. mode: '0400'
  116. owner: "{{ matrix_user_name }}"
  117. group: "{{ matrix_group_name }}"
  118. when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0
  119. register: matrix_hookshot_github_key_result
  120. - name: Ensure matrix-hookshot container network is created
  121. community.general.docker_network:
  122. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  123. name: "{{ matrix_hookshot_container_network }}"
  124. driver: bridge
  125. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  126. - name: Ensure mautrix-hookshot support files installed
  127. ansible.builtin.template:
  128. src: "{{ role_path }}/templates/{{ item }}.j2"
  129. dest: "{{ matrix_hookshot_base_path }}/{{ item }}"
  130. mode: '0640'
  131. owner: "{{ matrix_user_name }}"
  132. group: "{{ matrix_group_name }}"
  133. with_items:
  134. - labels
  135. register: matrix_hookshot_support_files_result
  136. - name: Ensure matrix-hookshot.service installed
  137. ansible.builtin.template:
  138. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  139. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  140. mode: '0644'
  141. register: matrix_hookshot_systemd_service_result
  142. - name: Determine whether matrix-hookshot needs a restart
  143. ansible.builtin.set_fact:
  144. matrix_hookshot_restart_necessary: >-
  145. {{
  146. matrix_hookshot_config_result.changed | default(false)
  147. or matrix_hookshot_registration_result.changed | default(false)
  148. or matrix_hookshot_github_key_result.changed | default(false)
  149. or matrix_hookshot_passkey_result.changed | default(false)
  150. or matrix_hookshot_support_files_result.changed | default(false)
  151. or matrix_hookshot_systemd_service_result.changed | default(false)
  152. or matrix_hookshot_container_image_pull_result.changed | default(false)
  153. or matrix_hookshot_container_image_build_result.changed | default(false)
  154. }}