Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

203 líneas
9.6 KiB

  1. # SPDX-FileCopyrightText: 2018 - 2025 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2018 Hugues Morisset
  3. # SPDX-FileCopyrightText: 2019 Aaron Raimist
  4. # SPDX-FileCopyrightText: 2019 Dan Arnfield
  5. # SPDX-FileCopyrightText: 2019 Jan Christian Grünhage
  6. # SPDX-FileCopyrightText: 2020 - 2022 MDAD project contributors
  7. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  8. # SPDX-FileCopyrightText: 2020 Stuart Mumford
  9. # SPDX-FileCopyrightText: 2021 Panagiotis Georgiadis
  10. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  11. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  12. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  13. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  14. # SPDX-FileCopyrightText: 2024 David Mehren
  15. #
  16. # SPDX-License-Identifier: AGPL-3.0-or-later
  17. ---
  18. - ansible.builtin.set_fact:
  19. matrix_mautrix_telegram_migration_requires_restart: false
  20. - when: "matrix_mautrix_telegram_database_engine == 'postgres'"
  21. block:
  22. - name: Check if an SQLite database already exists
  23. ansible.builtin.stat:
  24. path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  25. register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result
  26. - when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists | bool"
  27. block:
  28. - ansible.builtin.include_role:
  29. name: galaxy/postgres
  30. tasks_from: migrate_db_to_postgres
  31. vars:
  32. postgres_db_migration_request:
  33. src: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  34. dst: "{{ matrix_mautrix_telegram_database_connection_string }}"
  35. caller: "{{ role_path | basename }}"
  36. engine_variable_name: 'matrix_mautrix_telegram_database_engine'
  37. engine_old: 'sqlite'
  38. systemd_services_to_stop: ['matrix-mautrix-telegram.service']
  39. - ansible.builtin.set_fact:
  40. matrix_mautrix_telegram_migration_requires_restart: true
  41. - name: Ensure Mautrix Telegram paths exist
  42. ansible.builtin.file:
  43. path: "{{ item.path }}"
  44. state: directory
  45. mode: '0750'
  46. owner: "{{ matrix_user_name }}"
  47. group: "{{ matrix_group_name }}"
  48. with_items:
  49. - {path: "{{ matrix_mautrix_telegram_base_path }}", when: true}
  50. - {path: "{{ matrix_mautrix_telegram_config_path }}", when: true}
  51. - {path: "{{ matrix_mautrix_telegram_data_path }}", when: true}
  52. - {path: "{{ matrix_mautrix_telegram_container_src_files_path }}", when: "{{ matrix_mautrix_telegram_container_image_self_build }}"}
  53. when: item.when | bool
  54. - name: Ensure Mautrix Telegram image is pulled
  55. community.docker.docker_image:
  56. name: "{{ matrix_mautrix_telegram_container_image }}"
  57. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  58. force_source: "{{ matrix_mautrix_telegram_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  59. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_container_image_force_pull }}"
  60. when: "not matrix_mautrix_telegram_container_image_self_build | bool"
  61. register: matrix_mautrix_telegram_container_image_pull_result
  62. retries: "{{ devture_playbook_help_container_retries_count }}"
  63. delay: "{{ devture_playbook_help_container_retries_delay }}"
  64. until: matrix_mautrix_telegram_container_image_pull_result is not failed
  65. - name: Ensure lottieconverter is present when self-building
  66. ansible.builtin.git:
  67. repo: "{{ matrix_mautrix_telegram_lottieconverter_container_repo }}"
  68. version: "{{ matrix_mautrix_telegram_lottieconverter_container_repo_version }}"
  69. dest: "{{ matrix_mautrix_telegram_lottieconverter_container_src_files_path }}"
  70. force: "yes"
  71. become: true
  72. become_user: "{{ matrix_user_name }}"
  73. register: matrix_mautrix_telegram_lottieconverter_git_pull_results
  74. when: "matrix_mautrix_telegram_lottieconverter_container_image_self_build | bool and matrix_mautrix_telegram_container_image_self_build | bool"
  75. - name: Ensure lottieconverter Docker image is built
  76. community.docker.docker_image:
  77. name: "{{ matrix_mautrix_telegram_lottieconverter_container_image }}"
  78. source: build
  79. force_source: "{{ matrix_mautrix_telegram_lottieconverter_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  80. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_lottieconverter_git_pull_results.changed }}"
  81. build:
  82. dockerfile: Dockerfile
  83. path: "{{ matrix_mautrix_telegram_lottieconverter_container_src_files_path }}"
  84. pull: true
  85. when: "matrix_mautrix_telegram_lottieconverter_container_image_self_build | bool and matrix_mautrix_telegram_lottieconverter_git_pull_results.changed and matrix_mautrix_telegram_container_image_self_build | bool"
  86. - name: Ensure matrix-mautrix-telegram repository is present when self-building
  87. ansible.builtin.git:
  88. repo: "{{ matrix_mautrix_telegram_container_repo }}"
  89. version: "{{ matrix_mautrix_telegram_container_repo_version }}"
  90. dest: "{{ matrix_mautrix_telegram_container_src_files_path }}"
  91. force: "yes"
  92. become: true
  93. become_user: "{{ matrix_user_name }}"
  94. register: matrix_mautrix_telegram_git_pull_results
  95. when: "matrix_mautrix_telegram_container_image_self_build | bool"
  96. - name: Ensure matrix-mautrix-telegram Docker image is built
  97. community.docker.docker_image:
  98. name: "{{ matrix_mautrix_telegram_container_image }}"
  99. source: build
  100. force_source: "{{ matrix_mautrix_telegram_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  101. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_git_pull_results.changed }}"
  102. build:
  103. dockerfile: Dockerfile
  104. path: "{{ matrix_mautrix_telegram_container_src_files_path }}"
  105. pull: "{{ not matrix_mautrix_telegram_lottieconverter_container_image_self_build_mask_arch | bool }}"
  106. args:
  107. TARGETARCH: ""
  108. when: "matrix_mautrix_telegram_container_image_self_build | bool and matrix_mautrix_telegram_git_pull_results.changed"
  109. - name: Check if an old database file already exists
  110. ansible.builtin.stat:
  111. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  112. register: matrix_mautrix_telegram_stat_database
  113. - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped
  114. ansible.builtin.service:
  115. name: matrix-mautrix-telegram
  116. state: stopped
  117. enabled: false
  118. daemon_reload: true
  119. failed_when: false
  120. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  121. - name: (Data relocation) Move mautrix-telegram database file to ./data directory
  122. ansible.builtin.command:
  123. cmd: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  124. creates: "{{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  125. removes: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  126. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  127. - name: Ensure mautrix-telegram config.yaml installed
  128. ansible.builtin.copy:
  129. content: "{{ matrix_mautrix_telegram_configuration | to_nice_yaml(indent=2, width=999999) }}"
  130. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  131. mode: '0644'
  132. owner: "{{ matrix_user_name }}"
  133. group: "{{ matrix_group_name }}"
  134. register: matrix_mautrix_telegram_config_result
  135. - name: Ensure mautrix-telegram registration.yaml installed
  136. ansible.builtin.copy:
  137. content: "{{ matrix_mautrix_telegram_registration | to_nice_yaml(indent=2, width=999999) }}"
  138. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  139. mode: '0644'
  140. owner: "{{ matrix_user_name }}"
  141. group: "{{ matrix_group_name }}"
  142. register: matrix_mautrix_telegram_registration_result
  143. - name: Ensure mautrix-telegram support files installed
  144. ansible.builtin.template:
  145. src: "{{ role_path }}/templates/{{ item }}.j2"
  146. dest: "{{ matrix_mautrix_telegram_base_path }}/{{ item }}"
  147. mode: '0640'
  148. owner: "{{ matrix_user_name }}"
  149. group: "{{ matrix_group_name }}"
  150. with_items:
  151. - labels
  152. register: matrix_mautrix_telegram_support_files_result
  153. - name: Ensure matrix-mautrix-telegram container network is created
  154. community.general.docker_network:
  155. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  156. name: "{{ matrix_mautrix_telegram_container_network }}"
  157. driver: bridge
  158. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  159. - name: Ensure matrix-mautrix-telegram.service installed
  160. ansible.builtin.template:
  161. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  162. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-telegram.service"
  163. mode: '0644'
  164. register: matrix_mautrix_telegram_systemd_service_result
  165. - name: Determine whether matrix-mautrix-telegram needs a restart
  166. ansible.builtin.set_fact:
  167. matrix_mautrix_telegram_restart_necessary: >-
  168. {{
  169. matrix_mautrix_telegram_migration_requires_restart | default(false)
  170. or matrix_mautrix_telegram_config_result.changed | default(false)
  171. or matrix_mautrix_telegram_registration_result.changed | default(false)
  172. or matrix_mautrix_telegram_support_files_result.changed | default(false)
  173. or matrix_mautrix_telegram_systemd_service_result.changed | default(false)
  174. or matrix_mautrix_telegram_container_image_pull_result.changed | default(false)
  175. }}
  176. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  177. ansible.builtin.service:
  178. name: "matrix-mautrix-telegram.service"
  179. state: restarted
  180. daemon_reload: true
  181. when: "matrix_mautrix_telegram_migration_requires_restart | bool"