Matrix Docker Ansible eploy
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

184 linhas
8.7 KiB

  1. # SPDX-FileCopyrightText: 2021 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2021 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  6. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  7. # SPDX-FileCopyrightText: 2024 David Mehren
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - ansible.builtin.set_fact:
  12. matrix_bridge_mautrix_googlechat_migration_requires_restart: false
  13. - when: "matrix_bridge_mautrix_googlechat_database_engine == 'postgres'"
  14. block:
  15. - name: Check if an SQLite database already exists
  16. ansible.builtin.stat:
  17. path: "{{ matrix_bridge_mautrix_googlechat_sqlite_database_path_local }}"
  18. register: matrix_bridge_mautrix_googlechat_sqlite_database_path_local_stat_result
  19. - when: "matrix_bridge_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists | bool"
  20. block:
  21. - ansible.builtin.include_role:
  22. name: galaxy/postgres
  23. tasks_from: migrate_db_to_postgres
  24. vars:
  25. postgres_db_migration_request:
  26. src: "{{ matrix_bridge_mautrix_googlechat_sqlite_database_path_local }}"
  27. dst: "{{ matrix_bridge_mautrix_googlechat_database_connection_string }}"
  28. caller: "{{ role_path | basename }}"
  29. engine_variable_name: 'matrix_bridge_mautrix_googlechat_database_engine'
  30. engine_old: 'sqlite'
  31. systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
  32. - ansible.builtin.set_fact:
  33. matrix_bridge_mautrix_googlechat_migration_requires_restart: true
  34. - name: Ensure Mautrix googlechat image is pulled
  35. community.docker.docker_image_pull:
  36. name: "{{ matrix_bridge_mautrix_googlechat_container_image }}"
  37. pull: always
  38. when: not matrix_bridge_mautrix_googlechat_container_image_self_build
  39. register: matrix_bridge_mautrix_googlechat_container_image_pull_result
  40. retries: "{{ devture_playbook_help_container_retries_count }}"
  41. delay: "{{ devture_playbook_help_container_retries_delay }}"
  42. until: matrix_bridge_mautrix_googlechat_container_image_pull_result is not failed
  43. - name: Ensure Mautrix googlechat paths exist
  44. ansible.builtin.file:
  45. path: "{{ item.path }}"
  46. state: directory
  47. mode: '0750'
  48. owner: "{{ matrix_user_name }}"
  49. group: "{{ matrix_group_name }}"
  50. with_items:
  51. - {path: "{{ matrix_bridge_mautrix_googlechat_base_path }}", when: true}
  52. - {path: "{{ matrix_bridge_mautrix_googlechat_config_path }}", when: true}
  53. - {path: "{{ matrix_bridge_mautrix_googlechat_data_path }}", when: true}
  54. - {path: "{{ matrix_bridge_mautrix_googlechat_container_src_files_path }}", when: "{{ matrix_bridge_mautrix_googlechat_container_image_self_build }}"}
  55. when: "item.when | bool"
  56. # 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.
  57. - name: Ensure Mautrix Hangots repository ownership is correct on self build
  58. ansible.builtin.file:
  59. path: "{{ matrix_bridge_mautrix_googlechat_container_src_files_path }}"
  60. state: directory
  61. owner: "{{ matrix_user_name }}"
  62. group: "{{ matrix_group_name }}"
  63. recurse: true
  64. when: "matrix_bridge_mautrix_googlechat_container_image_self_build | bool"
  65. - name: Ensure Mautrix Hangots repository is present on self build
  66. ansible.builtin.git:
  67. repo: "{{ matrix_bridge_mautrix_googlechat_container_image_self_build_repo }}"
  68. version: "{{ matrix_bridge_mautrix_googlechat_container_image_self_build_repo_version }}"
  69. dest: "{{ matrix_bridge_mautrix_googlechat_container_src_files_path }}"
  70. force: "yes"
  71. become: true
  72. become_user: "{{ matrix_user_name }}"
  73. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  74. environment:
  75. GIT_CONFIG_COUNT: "1"
  76. GIT_CONFIG_KEY_0: safe.directory
  77. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_mautrix_googlechat_container_src_files_path }}"
  78. register: matrix_bridge_mautrix_googlechat_git_pull_results
  79. when: "matrix_bridge_mautrix_googlechat_container_image_self_build | bool"
  80. - name: Ensure Mautrix googlechat Docker image is built
  81. community.docker.docker_image_build:
  82. name: "{{ matrix_bridge_mautrix_googlechat_container_image }}"
  83. dockerfile: Dockerfile
  84. path: "{{ matrix_bridge_mautrix_googlechat_container_src_files_path }}"
  85. pull: true
  86. rebuild: "{{ 'always' if matrix_bridge_mautrix_googlechat_git_pull_results.changed | bool else 'never' }}"
  87. when: "matrix_bridge_mautrix_googlechat_container_image_self_build | bool"
  88. register: matrix_bridge_mautrix_googlechat_container_image_build_result
  89. - name: Check if an old database file already exists
  90. ansible.builtin.stat:
  91. path: "{{ matrix_bridge_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  92. register: matrix_bridge_mautrix_googlechat_stat_database
  93. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  94. ansible.builtin.service:
  95. name: matrix-mautrix-googlechat
  96. state: stopped
  97. enabled: false
  98. daemon_reload: true
  99. failed_when: false
  100. when: "matrix_bridge_mautrix_googlechat_stat_database.stat.exists"
  101. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  102. ansible.builtin.command:
  103. cmd: "mv {{ matrix_bridge_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_bridge_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  104. creates: "{{ matrix_bridge_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  105. removes: "{{ matrix_bridge_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  106. when: "matrix_bridge_mautrix_googlechat_stat_database.stat.exists"
  107. - name: Ensure mautrix-googlechat config.yaml installed
  108. ansible.builtin.copy:
  109. content: "{{ matrix_bridge_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  110. dest: "{{ matrix_bridge_mautrix_googlechat_config_path }}/config.yaml"
  111. mode: '0644'
  112. owner: "{{ matrix_user_name }}"
  113. group: "{{ matrix_group_name }}"
  114. register: matrix_bridge_mautrix_googlechat_config_result
  115. - name: Ensure mautrix-googlechat registration.yaml installed
  116. ansible.builtin.copy:
  117. content: "{{ matrix_bridge_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  118. dest: "{{ matrix_bridge_mautrix_googlechat_config_path }}/registration.yaml"
  119. mode: '0644'
  120. owner: "{{ matrix_user_name }}"
  121. group: "{{ matrix_group_name }}"
  122. register: matrix_bridge_mautrix_googlechat_registration_result
  123. - name: Ensure mautrix-googlechat support files installed
  124. ansible.builtin.template:
  125. src: "{{ role_path }}/templates/{{ item }}.j2"
  126. dest: "{{ matrix_bridge_mautrix_googlechat_base_path }}/{{ item }}"
  127. mode: '0640'
  128. owner: "{{ matrix_user_name }}"
  129. group: "{{ matrix_group_name }}"
  130. with_items:
  131. - labels
  132. register: matrix_bridge_mautrix_googlechat_support_files_result
  133. - name: Ensure matrix-mautrix-googlechat container network is created
  134. when: matrix_bridge_mautrix_googlechat_container_network != 'host'
  135. community.general.docker_network:
  136. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  137. name: "{{ matrix_bridge_mautrix_googlechat_container_network }}"
  138. driver: bridge
  139. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  140. - name: Ensure matrix-mautrix-googlechat.service installed
  141. ansible.builtin.template:
  142. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  143. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  144. mode: '0644'
  145. register: matrix_bridge_mautrix_googlechat_systemd_service_result
  146. - name: Determine whether matrix-mautrix-googlechat needs a restart
  147. ansible.builtin.set_fact:
  148. matrix_bridge_mautrix_googlechat_restart_necessary: >-
  149. {{
  150. matrix_bridge_mautrix_googlechat_migration_requires_restart | default(false)
  151. or matrix_bridge_mautrix_googlechat_config_result.changed | default(false)
  152. or matrix_bridge_mautrix_googlechat_registration_result.changed | default(false)
  153. or matrix_bridge_mautrix_googlechat_support_files_result.changed | default(false)
  154. or matrix_bridge_mautrix_googlechat_systemd_service_result.changed | default(false)
  155. or matrix_bridge_mautrix_googlechat_container_image_pull_result.changed | default(false)
  156. or matrix_bridge_mautrix_googlechat_container_image_build_result.changed | default(false)
  157. }}
  158. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  159. ansible.builtin.service:
  160. name: "matrix-mautrix-googlechat.service"
  161. state: restarted
  162. daemon_reload: true
  163. when: "matrix_bridge_mautrix_googlechat_migration_requires_restart | bool"