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

189 строки
8.5 KiB

  1. # SPDX-FileCopyrightText: 2018 - 2026 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. # The legacy Python bridge stored its SQLite DB at `{base_path}/mautrix-telegram.db` (the role's
  21. # root). Later, we started relocating it to `{base_path}/data/mautrix-telegram.db`. The sqlite→
  22. # postgres migration below only knows about the new path, so if the DB is still at the legacy
  23. # location, move it to the new location first — otherwise users who follow the changelog and
  24. # switch to Postgres wouldn't actually get their data imported before the service starts.
  25. - name: Check if a legacy-location SQLite database exists
  26. ansible.builtin.stat:
  27. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  28. register: matrix_mautrix_telegram_stat_database_legacy_location
  29. - when: matrix_mautrix_telegram_stat_database_legacy_location.stat.exists | bool
  30. block:
  31. - name: Ensure matrix-mautrix-telegram.service is stopped before relocating legacy SQLite DB
  32. ansible.builtin.service:
  33. name: matrix-mautrix-telegram
  34. state: stopped
  35. enabled: false
  36. daemon_reload: true
  37. failed_when: false
  38. - name: Ensure data directory exists for legacy SQLite DB relocation
  39. ansible.builtin.file:
  40. path: "{{ matrix_mautrix_telegram_data_path }}"
  41. state: directory
  42. mode: '0750'
  43. owner: "{{ matrix_user_name }}"
  44. group: "{{ matrix_group_name }}"
  45. - name: (Data relocation) Move mautrix-telegram SQLite DB from legacy location to data directory
  46. ansible.builtin.command:
  47. cmd: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  48. creates: "{{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  49. removes: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  50. - when: "matrix_mautrix_telegram_database_engine == 'postgres'"
  51. block:
  52. - name: Check if an SQLite database already exists
  53. ansible.builtin.stat:
  54. path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  55. register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result
  56. - when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists | bool"
  57. block:
  58. - ansible.builtin.include_role:
  59. name: galaxy/postgres
  60. tasks_from: migrate_db_to_postgres
  61. vars:
  62. postgres_db_migration_request:
  63. src: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  64. dst: "{{ matrix_mautrix_telegram_database_connection_string }}"
  65. caller: "{{ role_path | basename }}"
  66. engine_variable_name: 'matrix_mautrix_telegram_database_engine'
  67. engine_old: 'sqlite'
  68. systemd_services_to_stop: ['matrix-mautrix-telegram.service']
  69. pgloader_options: ['--with "quote identifiers"']
  70. - ansible.builtin.set_fact:
  71. matrix_mautrix_telegram_migration_requires_restart: true
  72. - name: Ensure Mautrix Telegram paths exist
  73. ansible.builtin.file:
  74. path: "{{ item.path }}"
  75. state: directory
  76. mode: '0750'
  77. owner: "{{ matrix_user_name }}"
  78. group: "{{ matrix_group_name }}"
  79. with_items:
  80. - {path: "{{ matrix_mautrix_telegram_base_path }}", when: true}
  81. - {path: "{{ matrix_mautrix_telegram_config_path }}", when: true}
  82. - {path: "{{ matrix_mautrix_telegram_data_path }}", when: true}
  83. - {path: "{{ matrix_mautrix_telegram_container_src_files_path }}", when: "{{ matrix_mautrix_telegram_container_image_self_build }}"}
  84. when: item.when | bool
  85. - name: Ensure Mautrix Telegram image is pulled
  86. community.docker.docker_image_pull:
  87. name: "{{ matrix_mautrix_telegram_container_image }}"
  88. pull: always
  89. when: "not matrix_mautrix_telegram_container_image_self_build | bool"
  90. register: matrix_mautrix_telegram_container_image_pull_result
  91. retries: "{{ devture_playbook_help_container_retries_count }}"
  92. delay: "{{ devture_playbook_help_container_retries_delay }}"
  93. until: matrix_mautrix_telegram_container_image_pull_result is not failed
  94. - name: Ensure Mautrix Telegram repository is present on self-build
  95. ansible.builtin.git:
  96. repo: "{{ matrix_mautrix_telegram_container_image_self_build_repo }}"
  97. dest: "{{ matrix_mautrix_telegram_container_src_files_path }}"
  98. version: "{{ matrix_mautrix_telegram_container_image_self_build_branch }}"
  99. force: "yes"
  100. become: true
  101. become_user: "{{ matrix_user_name }}"
  102. register: matrix_mautrix_telegram_git_pull_results
  103. when: "matrix_mautrix_telegram_container_image_self_build | bool"
  104. - name: Ensure Mautrix Telegram Docker image is built
  105. community.docker.docker_image_build:
  106. name: "{{ matrix_mautrix_telegram_container_image }}"
  107. dockerfile: Dockerfile
  108. path: "{{ matrix_mautrix_telegram_container_src_files_path }}"
  109. pull: true
  110. rebuild: "{{ 'always' if matrix_mautrix_telegram_git_pull_results.changed | bool else 'never' }}"
  111. when: "matrix_mautrix_telegram_container_image_self_build | bool"
  112. register: matrix_mautrix_telegram_container_image_build_result
  113. - name: Ensure mautrix-telegram config.yaml installed
  114. ansible.builtin.copy:
  115. content: "{{ matrix_mautrix_telegram_configuration | to_nice_yaml(indent=2, width=999999) }}"
  116. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  117. mode: '0644'
  118. owner: "{{ matrix_user_name }}"
  119. group: "{{ matrix_group_name }}"
  120. register: matrix_mautrix_telegram_config_result
  121. - name: Ensure mautrix-telegram registration.yaml installed
  122. ansible.builtin.copy:
  123. content: "{{ matrix_mautrix_telegram_registration | to_nice_yaml(indent=2, width=999999) }}"
  124. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  125. mode: '0644'
  126. owner: "{{ matrix_user_name }}"
  127. group: "{{ matrix_group_name }}"
  128. register: matrix_mautrix_telegram_registration_result
  129. - name: Ensure mautrix-telegram support files installed
  130. ansible.builtin.template:
  131. src: "{{ role_path }}/templates/{{ item }}.j2"
  132. dest: "{{ matrix_mautrix_telegram_base_path }}/{{ item }}"
  133. mode: '0640'
  134. owner: "{{ matrix_user_name }}"
  135. group: "{{ matrix_group_name }}"
  136. with_items:
  137. - labels
  138. register: matrix_mautrix_telegram_support_files_result
  139. - name: Ensure matrix-mautrix-telegram container network is created
  140. community.general.docker_network:
  141. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  142. name: "{{ matrix_mautrix_telegram_container_network }}"
  143. driver: bridge
  144. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  145. - name: Ensure matrix-mautrix-telegram.service installed
  146. ansible.builtin.template:
  147. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  148. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-telegram.service"
  149. mode: '0644'
  150. register: matrix_mautrix_telegram_systemd_service_result
  151. - name: Determine whether matrix-mautrix-telegram needs a restart
  152. ansible.builtin.set_fact:
  153. matrix_mautrix_telegram_restart_necessary: >-
  154. {{
  155. matrix_mautrix_telegram_migration_requires_restart | default(false)
  156. or matrix_mautrix_telegram_config_result.changed | default(false)
  157. or matrix_mautrix_telegram_registration_result.changed | default(false)
  158. or matrix_mautrix_telegram_support_files_result.changed | default(false)
  159. or matrix_mautrix_telegram_systemd_service_result.changed | default(false)
  160. or matrix_mautrix_telegram_container_image_pull_result.changed | default(false)
  161. or matrix_mautrix_telegram_container_image_build_result.changed | default(false)
  162. }}
  163. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  164. ansible.builtin.service:
  165. name: "matrix-mautrix-telegram.service"
  166. state: restarted
  167. daemon_reload: true
  168. when: "matrix_mautrix_telegram_migration_requires_restart | bool"