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

184 строки
8.0 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_bridge_hookshot_base_path }}", when: true}
  25. - {path: "{{ matrix_bridge_hookshot_container_src_files_path }}", when: "{{ matrix_bridge_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_bridge_hookshot_container_image }}"
  30. pull: always
  31. when: not matrix_bridge_hookshot_container_image_self_build
  32. register: matrix_bridge_hookshot_container_image_pull_result
  33. retries: "{{ devture_playbook_help_container_retries_count }}"
  34. delay: "{{ devture_playbook_help_container_retries_delay }}"
  35. until: matrix_bridge_hookshot_container_image_pull_result is not failed
  36. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  37. - name: Ensure hookshot repository ownership is correct on self-build
  38. ansible.builtin.file:
  39. path: "{{ matrix_bridge_hookshot_container_src_files_path }}"
  40. state: directory
  41. owner: "{{ matrix_user_name }}"
  42. group: "{{ matrix_group_name }}"
  43. recurse: true
  44. when: "matrix_bridge_hookshot_container_image_self_build | bool"
  45. - name: Ensure hookshot repository is present on self-build
  46. ansible.builtin.git:
  47. repo: "{{ matrix_bridge_hookshot_container_image_self_build_repo }}"
  48. dest: "{{ matrix_bridge_hookshot_container_src_files_path }}"
  49. version: "{{ matrix_bridge_hookshot_container_image_self_build_branch }}"
  50. force: "yes"
  51. become: true
  52. become_user: "{{ matrix_user_name }}"
  53. register: matrix_bridge_hookshot_git_pull_results
  54. when: "matrix_bridge_hookshot_container_image_self_build | bool"
  55. - name: Ensure hookshot Docker image is built
  56. community.docker.docker_image_build:
  57. name: "{{ matrix_bridge_hookshot_container_image }}"
  58. dockerfile: Dockerfile
  59. path: "{{ matrix_bridge_hookshot_container_src_files_path }}"
  60. pull: true
  61. rebuild: "{{ 'always' if matrix_bridge_hookshot_git_pull_results.changed | bool else 'never' }}"
  62. when: "matrix_bridge_hookshot_container_image_self_build | bool"
  63. register: matrix_bridge_hookshot_container_image_build_result
  64. - name: Check if hookshot passkey exists
  65. ansible.builtin.stat:
  66. path: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  67. register: hookshot_passkey_file
  68. - name: Generate hookshot passkey if it doesn't exist
  69. ansible.builtin.shell:
  70. cmd: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_bridge_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  71. creates: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  72. become: true
  73. become_user: "{{ matrix_user_name }}"
  74. when: "not hookshot_passkey_file.stat.exists"
  75. # We intentionally reconcile the passkey ownership/mode after generation,
  76. # because some setups can end up creating host-side files as the SSH user
  77. # instead of `matrix` when `become_user` is effectively not honored.
  78. #
  79. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5033
  80. - name: Ensure hookshot passkey has correct ownership and mode
  81. ansible.builtin.file:
  82. path: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  83. state: file
  84. mode: '0600'
  85. owner: "{{ matrix_user_name }}"
  86. group: "{{ matrix_group_name }}"
  87. register: matrix_bridge_hookshot_passkey_result
  88. - name: Ensure hookshot config.yml installed if provided
  89. ansible.builtin.copy:
  90. content: "{{ matrix_bridge_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  91. dest: "{{ matrix_bridge_hookshot_base_path }}/config.yml"
  92. mode: '0644'
  93. owner: "{{ matrix_user_name }}"
  94. group: "{{ matrix_group_name }}"
  95. register: matrix_bridge_hookshot_config_result
  96. - name: Validate hookshot config.yml
  97. ansible.builtin.command:
  98. cmd: |
  99. {{ devture_systemd_docker_base_host_command_docker }} run
  100. --rm
  101. --name={{ matrix_bridge_hookshot_container_url }}-validate
  102. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  103. --cap-drop=ALL
  104. --mount type=bind,src={{ matrix_bridge_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  105. {{ matrix_bridge_hookshot_container_image }} node config/Config.js /config.yml
  106. register: hookshot_config_validation_result
  107. changed_when: false
  108. - name: Fail if hookshot config.yml invalid
  109. ansible.builtin.fail:
  110. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  111. when: "hookshot_config_validation_result.rc > 0"
  112. - name: Ensure hookshot registration.yml installed if provided
  113. ansible.builtin.copy:
  114. content: "{{ matrix_bridge_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  115. dest: "{{ matrix_bridge_hookshot_base_path }}/registration.yml"
  116. mode: '0644'
  117. owner: "{{ matrix_user_name }}"
  118. group: "{{ matrix_group_name }}"
  119. register: matrix_bridge_hookshot_registration_result
  120. - name: Ensure hookshot github private key file installed if github is enabled
  121. ansible.builtin.copy:
  122. content: "{{ matrix_bridge_hookshot_github_private_key }}"
  123. dest: "{{ matrix_bridge_hookshot_base_path }}/{{ matrix_bridge_hookshot_github_private_key_file }}"
  124. mode: '0400'
  125. owner: "{{ matrix_user_name }}"
  126. group: "{{ matrix_group_name }}"
  127. when: matrix_bridge_hookshot_github_enabled | bool and matrix_bridge_hookshot_github_private_key|length > 0
  128. register: matrix_bridge_hookshot_github_key_result
  129. - name: Ensure matrix-hookshot container network is created
  130. when: matrix_bridge_hookshot_container_network != 'host'
  131. community.general.docker_network:
  132. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  133. name: "{{ matrix_bridge_hookshot_container_network }}"
  134. driver: bridge
  135. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  136. - name: Ensure mautrix-hookshot support files installed
  137. ansible.builtin.template:
  138. src: "{{ role_path }}/templates/{{ item }}.j2"
  139. dest: "{{ matrix_bridge_hookshot_base_path }}/{{ item }}"
  140. mode: '0640'
  141. owner: "{{ matrix_user_name }}"
  142. group: "{{ matrix_group_name }}"
  143. with_items:
  144. - labels
  145. register: matrix_bridge_hookshot_support_files_result
  146. - name: Ensure matrix-hookshot.service installed
  147. ansible.builtin.template:
  148. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  149. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  150. mode: '0644'
  151. register: matrix_bridge_hookshot_systemd_service_result
  152. - name: Determine whether matrix-hookshot needs a restart
  153. ansible.builtin.set_fact:
  154. matrix_bridge_hookshot_restart_necessary: >-
  155. {{
  156. matrix_bridge_hookshot_config_result.changed | default(false)
  157. or matrix_bridge_hookshot_registration_result.changed | default(false)
  158. or matrix_bridge_hookshot_github_key_result.changed | default(false)
  159. or matrix_bridge_hookshot_passkey_result.changed | default(false)
  160. or matrix_bridge_hookshot_support_files_result.changed | default(false)
  161. or matrix_bridge_hookshot_systemd_service_result.changed | default(false)
  162. or matrix_bridge_hookshot_container_image_pull_result.changed | default(false)
  163. or matrix_bridge_hookshot_container_image_build_result.changed | default(false)
  164. }}