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

176 строки
7.5 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:
  29. name: "{{ matrix_hookshot_container_image }}"
  30. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  31. force_source: "{{ matrix_hookshot_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  32. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_hookshot_container_image_force_pull }}"
  33. when: not matrix_hookshot_container_image_self_build
  34. register: matrix_hookshot_container_image_pull_result
  35. retries: "{{ devture_playbook_help_container_retries_count }}"
  36. delay: "{{ devture_playbook_help_container_retries_delay }}"
  37. until: matrix_hookshot_container_image_pull_result is not failed
  38. - name: Ensure hookshot repository is present on self-build
  39. ansible.builtin.git:
  40. repo: "{{ matrix_hookshot_container_image_self_build_repo }}"
  41. dest: "{{ matrix_hookshot_container_src_files_path }}"
  42. version: "{{ matrix_hookshot_container_image_self_build_branch }}"
  43. force: "yes"
  44. become: true
  45. become_user: "{{ matrix_user_name }}"
  46. register: matrix_hookshot_git_pull_results
  47. when: "matrix_hookshot_container_image_self_build | bool"
  48. - name: Ensure hookshot Docker image is built
  49. community.docker.docker_image:
  50. name: "{{ matrix_hookshot_container_image }}"
  51. source: build
  52. force_source: "{{ matrix_hookshot_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  53. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_hookshot_git_pull_results.changed }}"
  54. build:
  55. dockerfile: Dockerfile
  56. path: "{{ matrix_hookshot_container_src_files_path }}"
  57. pull: true
  58. when: "matrix_hookshot_container_image_self_build | bool"
  59. - name: Check if hookshot passkey exists
  60. ansible.builtin.stat:
  61. path: "{{ matrix_hookshot_base_path }}/passkey.pem"
  62. register: hookshot_passkey_file
  63. - name: Generate hookshot passkey if it doesn't exist
  64. ansible.builtin.shell:
  65. cmd: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  66. creates: "{{ matrix_hookshot_base_path }}/passkey.pem"
  67. become: true
  68. become_user: "{{ matrix_user_name }}"
  69. when: "not hookshot_passkey_file.stat.exists"
  70. # We intentionally reconcile the passkey ownership/mode after generation,
  71. # because some setups can end up creating host-side files as the SSH user
  72. # instead of `matrix` when `become_user` is effectively not honored.
  73. #
  74. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5033
  75. - name: Ensure hookshot passkey has correct ownership and mode
  76. ansible.builtin.file:
  77. path: "{{ matrix_hookshot_base_path }}/passkey.pem"
  78. state: file
  79. mode: '0600'
  80. owner: "{{ matrix_user_name }}"
  81. group: "{{ matrix_group_name }}"
  82. register: matrix_hookshot_passkey_result
  83. - name: Ensure hookshot config.yml installed if provided
  84. ansible.builtin.copy:
  85. content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  86. dest: "{{ matrix_hookshot_base_path }}/config.yml"
  87. mode: '0644'
  88. owner: "{{ matrix_user_name }}"
  89. group: "{{ matrix_group_name }}"
  90. register: matrix_hookshot_config_result
  91. - name: Validate hookshot config.yml
  92. ansible.builtin.command:
  93. cmd: |
  94. {{ devture_systemd_docker_base_host_command_docker }} run
  95. --rm
  96. --name={{ matrix_hookshot_container_url }}-validate
  97. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  98. --cap-drop=ALL
  99. --mount type=bind,src={{ matrix_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  100. {{ matrix_hookshot_container_image }} node config/Config.js /config.yml
  101. register: hookshot_config_validation_result
  102. changed_when: false
  103. - name: Fail if hookshot config.yml invalid
  104. ansible.builtin.fail:
  105. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  106. when: "hookshot_config_validation_result.rc > 0"
  107. - name: Ensure hookshot registration.yml installed if provided
  108. ansible.builtin.copy:
  109. content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  110. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  111. mode: '0644'
  112. owner: "{{ matrix_user_name }}"
  113. group: "{{ matrix_group_name }}"
  114. register: matrix_hookshot_registration_result
  115. - name: Ensure hookshot github private key file installed if github is enabled
  116. ansible.builtin.copy:
  117. content: "{{ matrix_hookshot_github_private_key }}"
  118. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  119. mode: '0400'
  120. owner: "{{ matrix_user_name }}"
  121. group: "{{ matrix_group_name }}"
  122. when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0
  123. register: matrix_hookshot_github_key_result
  124. - name: Ensure matrix-hookshot container network is created
  125. community.general.docker_network:
  126. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  127. name: "{{ matrix_hookshot_container_network }}"
  128. driver: bridge
  129. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  130. - name: Ensure mautrix-hookshot support files installed
  131. ansible.builtin.template:
  132. src: "{{ role_path }}/templates/{{ item }}.j2"
  133. dest: "{{ matrix_hookshot_base_path }}/{{ item }}"
  134. mode: '0640'
  135. owner: "{{ matrix_user_name }}"
  136. group: "{{ matrix_group_name }}"
  137. with_items:
  138. - labels
  139. register: matrix_hookshot_support_files_result
  140. - name: Ensure matrix-hookshot.service installed
  141. ansible.builtin.template:
  142. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  143. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  144. mode: '0644'
  145. register: matrix_hookshot_systemd_service_result
  146. - name: Determine whether matrix-hookshot needs a restart
  147. ansible.builtin.set_fact:
  148. matrix_hookshot_restart_necessary: >-
  149. {{
  150. matrix_hookshot_config_result.changed | default(false)
  151. or matrix_hookshot_registration_result.changed | default(false)
  152. or matrix_hookshot_github_key_result.changed | default(false)
  153. or matrix_hookshot_passkey_result.changed | default(false)
  154. or matrix_hookshot_support_files_result.changed | default(false)
  155. or matrix_hookshot_systemd_service_result.changed | default(false)
  156. or matrix_hookshot_container_image_pull_result.changed | default(false)
  157. }}