Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

161 řádky
6.8 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_docker_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_docker_image }}"
  30. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  31. force_source: "{{ matrix_hookshot_docker_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_docker_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_docker_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_docker_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_docker_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. - name: Ensure hookshot config.yml installed if provided
  71. ansible.builtin.copy:
  72. content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  73. dest: "{{ matrix_hookshot_base_path }}/config.yml"
  74. mode: '0644'
  75. owner: "{{ matrix_user_name }}"
  76. group: "{{ matrix_group_name }}"
  77. register: matrix_hookshot_config_result
  78. - name: Validate hookshot config.yml
  79. ansible.builtin.command:
  80. cmd: |
  81. {{ devture_systemd_docker_base_host_command_docker }} run
  82. --rm
  83. --name={{ matrix_hookshot_container_url }}-validate
  84. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  85. --cap-drop=ALL
  86. --mount type=bind,src={{ matrix_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  87. {{ matrix_hookshot_docker_image }} node config/Config.js /config.yml
  88. register: hookshot_config_validation_result
  89. changed_when: false
  90. - name: Fail if hookshot config.yml invalid
  91. ansible.builtin.fail:
  92. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  93. when: "hookshot_config_validation_result.rc > 0"
  94. - name: Ensure hookshot registration.yml installed if provided
  95. ansible.builtin.copy:
  96. content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  97. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  98. mode: '0644'
  99. owner: "{{ matrix_user_name }}"
  100. group: "{{ matrix_group_name }}"
  101. register: matrix_hookshot_registration_result
  102. - name: Ensure hookshot github private key file installed if github is enabled
  103. ansible.builtin.copy:
  104. content: "{{ matrix_hookshot_github_private_key }}"
  105. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  106. mode: '0400'
  107. owner: "{{ matrix_user_name }}"
  108. group: "{{ matrix_group_name }}"
  109. when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0
  110. register: matrix_hookshot_github_key_result
  111. - name: Ensure matrix-hookshot container network is created
  112. community.general.docker_network:
  113. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  114. name: "{{ matrix_hookshot_container_network }}"
  115. driver: bridge
  116. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  117. - name: Ensure mautrix-hookshot support files installed
  118. ansible.builtin.template:
  119. src: "{{ role_path }}/templates/{{ item }}.j2"
  120. dest: "{{ matrix_hookshot_base_path }}/{{ item }}"
  121. mode: '0640'
  122. owner: "{{ matrix_user_name }}"
  123. group: "{{ matrix_group_name }}"
  124. with_items:
  125. - labels
  126. register: matrix_hookshot_support_files_result
  127. - name: Ensure matrix-hookshot.service installed
  128. ansible.builtin.template:
  129. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  130. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  131. mode: '0644'
  132. register: matrix_hookshot_systemd_service_result
  133. - name: Determine whether matrix-hookshot needs a restart
  134. ansible.builtin.set_fact:
  135. matrix_hookshot_restart_necessary: >-
  136. {{
  137. matrix_hookshot_config_result.changed | default(false)
  138. or matrix_hookshot_registration_result.changed | default(false)
  139. or matrix_hookshot_github_key_result.changed | default(false)
  140. or matrix_hookshot_support_files_result.changed | default(false)
  141. or matrix_hookshot_systemd_service_result.changed | default(false)
  142. or matrix_hookshot_container_image_pull_result.changed | default(false)
  143. }}