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

189 строки
8.3 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. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  54. environment:
  55. GIT_CONFIG_COUNT: "1"
  56. GIT_CONFIG_KEY_0: safe.directory
  57. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_hookshot_container_src_files_path }}"
  58. register: matrix_bridge_hookshot_git_pull_results
  59. when: "matrix_bridge_hookshot_container_image_self_build | bool"
  60. - name: Ensure hookshot Docker image is built
  61. community.docker.docker_image_build:
  62. name: "{{ matrix_bridge_hookshot_container_image }}"
  63. dockerfile: Dockerfile
  64. path: "{{ matrix_bridge_hookshot_container_src_files_path }}"
  65. pull: true
  66. rebuild: "{{ 'always' if matrix_bridge_hookshot_git_pull_results.changed | bool else 'never' }}"
  67. when: "matrix_bridge_hookshot_container_image_self_build | bool"
  68. register: matrix_bridge_hookshot_container_image_build_result
  69. - name: Check if hookshot passkey exists
  70. ansible.builtin.stat:
  71. path: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  72. register: hookshot_passkey_file
  73. - name: Generate hookshot passkey if it doesn't exist
  74. ansible.builtin.shell:
  75. cmd: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_bridge_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  76. creates: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  77. become: true
  78. become_user: "{{ matrix_user_name }}"
  79. when: "not hookshot_passkey_file.stat.exists"
  80. # We intentionally reconcile the passkey ownership/mode after generation,
  81. # because some setups can end up creating host-side files as the SSH user
  82. # instead of `matrix` when `become_user` is effectively not honored.
  83. #
  84. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5033
  85. - name: Ensure hookshot passkey has correct ownership and mode
  86. ansible.builtin.file:
  87. path: "{{ matrix_bridge_hookshot_base_path }}/passkey.pem"
  88. state: file
  89. mode: '0600'
  90. owner: "{{ matrix_user_name }}"
  91. group: "{{ matrix_group_name }}"
  92. register: matrix_bridge_hookshot_passkey_result
  93. - name: Ensure hookshot config.yml installed if provided
  94. ansible.builtin.copy:
  95. content: "{{ matrix_bridge_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  96. dest: "{{ matrix_bridge_hookshot_base_path }}/config.yml"
  97. mode: '0644'
  98. owner: "{{ matrix_user_name }}"
  99. group: "{{ matrix_group_name }}"
  100. register: matrix_bridge_hookshot_config_result
  101. - name: Validate hookshot config.yml
  102. ansible.builtin.command:
  103. cmd: |
  104. {{ devture_systemd_docker_base_host_command_docker }} run
  105. --rm
  106. --name={{ matrix_bridge_hookshot_container_url }}-validate
  107. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  108. --cap-drop=ALL
  109. --mount type=bind,src={{ matrix_bridge_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  110. {{ matrix_bridge_hookshot_container_image }} node config/Config.js /config.yml
  111. register: hookshot_config_validation_result
  112. changed_when: false
  113. - name: Fail if hookshot config.yml invalid
  114. ansible.builtin.fail:
  115. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  116. when: "hookshot_config_validation_result.rc > 0"
  117. - name: Ensure hookshot registration.yml installed if provided
  118. ansible.builtin.copy:
  119. content: "{{ matrix_bridge_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  120. dest: "{{ matrix_bridge_hookshot_base_path }}/registration.yml"
  121. mode: '0644'
  122. owner: "{{ matrix_user_name }}"
  123. group: "{{ matrix_group_name }}"
  124. register: matrix_bridge_hookshot_registration_result
  125. - name: Ensure hookshot github private key file installed if github is enabled
  126. ansible.builtin.copy:
  127. content: "{{ matrix_bridge_hookshot_github_private_key }}"
  128. dest: "{{ matrix_bridge_hookshot_base_path }}/{{ matrix_bridge_hookshot_github_private_key_file }}"
  129. mode: '0400'
  130. owner: "{{ matrix_user_name }}"
  131. group: "{{ matrix_group_name }}"
  132. when: matrix_bridge_hookshot_github_enabled | bool and matrix_bridge_hookshot_github_private_key|length > 0
  133. register: matrix_bridge_hookshot_github_key_result
  134. - name: Ensure matrix-hookshot container network is created
  135. when: matrix_bridge_hookshot_container_network != 'host'
  136. community.general.docker_network:
  137. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  138. name: "{{ matrix_bridge_hookshot_container_network }}"
  139. driver: bridge
  140. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  141. - name: Ensure hookshot support files installed
  142. ansible.builtin.template:
  143. src: "{{ role_path }}/templates/{{ item }}.j2"
  144. dest: "{{ matrix_bridge_hookshot_base_path }}/{{ item }}"
  145. mode: '0640'
  146. owner: "{{ matrix_user_name }}"
  147. group: "{{ matrix_group_name }}"
  148. with_items:
  149. - labels
  150. register: matrix_bridge_hookshot_support_files_result
  151. - name: Ensure matrix-hookshot.service installed
  152. ansible.builtin.template:
  153. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  154. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  155. mode: '0644'
  156. register: matrix_bridge_hookshot_systemd_service_result
  157. - name: Determine whether matrix-hookshot needs a restart
  158. ansible.builtin.set_fact:
  159. matrix_bridge_hookshot_restart_necessary: >-
  160. {{
  161. matrix_bridge_hookshot_config_result.changed | default(false)
  162. or matrix_bridge_hookshot_registration_result.changed | default(false)
  163. or matrix_bridge_hookshot_github_key_result.changed | default(false)
  164. or matrix_bridge_hookshot_passkey_result.changed | default(false)
  165. or matrix_bridge_hookshot_support_files_result.changed | default(false)
  166. or matrix_bridge_hookshot_systemd_service_result.changed | default(false)
  167. or matrix_bridge_hookshot_container_image_pull_result.changed | default(false)
  168. or matrix_bridge_hookshot_container_image_build_result.changed | default(false)
  169. }}