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

168 строки
7.4 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_mautrix_googlechat_migration_requires_restart: false
  13. - when: "matrix_mautrix_googlechat_database_engine == 'postgres'"
  14. block:
  15. - name: Check if an SQLite database already exists
  16. ansible.builtin.stat:
  17. path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  18. register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result
  19. - when: "matrix_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_mautrix_googlechat_sqlite_database_path_local }}"
  27. dst: "{{ matrix_mautrix_googlechat_database_connection_string }}"
  28. caller: "{{ role_path | basename }}"
  29. engine_variable_name: 'matrix_mautrix_googlechat_database_engine'
  30. engine_old: 'sqlite'
  31. systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
  32. - ansible.builtin.set_fact:
  33. matrix_mautrix_googlechat_migration_requires_restart: true
  34. - name: Ensure Mautrix googlechat image is pulled
  35. community.docker.docker_image_pull:
  36. name: "{{ matrix_mautrix_googlechat_container_image }}"
  37. pull: always
  38. when: not matrix_mautrix_googlechat_container_image_self_build
  39. register: matrix_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_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_mautrix_googlechat_base_path }}", when: true}
  52. - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true}
  53. - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true}
  54. - {path: "{{ matrix_mautrix_googlechat_container_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"}
  55. when: "item.when | bool"
  56. - name: Ensure Mautrix Hangots repository is present on self build
  57. ansible.builtin.git:
  58. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  59. version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}"
  60. dest: "{{ matrix_mautrix_googlechat_container_src_files_path }}"
  61. force: "yes"
  62. become: true
  63. become_user: "{{ matrix_user_name }}"
  64. register: matrix_mautrix_googlechat_git_pull_results
  65. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  66. - name: Ensure Mautrix googlechat Docker image is built
  67. community.docker.docker_image_build:
  68. name: "{{ matrix_mautrix_googlechat_container_image }}"
  69. dockerfile: Dockerfile
  70. path: "{{ matrix_mautrix_googlechat_container_src_files_path }}"
  71. pull: true
  72. rebuild: "{{ 'always' if matrix_mautrix_googlechat_git_pull_results.changed | bool else 'never' }}"
  73. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  74. register: matrix_mautrix_googlechat_container_image_build_result
  75. - name: Check if an old database file already exists
  76. ansible.builtin.stat:
  77. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  78. register: matrix_mautrix_googlechat_stat_database
  79. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  80. ansible.builtin.service:
  81. name: matrix-mautrix-googlechat
  82. state: stopped
  83. enabled: false
  84. daemon_reload: true
  85. failed_when: false
  86. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  87. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  88. ansible.builtin.command:
  89. cmd: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  90. creates: "{{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  91. removes: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  92. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  93. - name: Ensure mautrix-googlechat config.yaml installed
  94. ansible.builtin.copy:
  95. content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  96. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  97. mode: '0644'
  98. owner: "{{ matrix_user_name }}"
  99. group: "{{ matrix_group_name }}"
  100. register: matrix_mautrix_googlechat_config_result
  101. - name: Ensure mautrix-googlechat registration.yaml installed
  102. ansible.builtin.copy:
  103. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  104. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  105. mode: '0644'
  106. owner: "{{ matrix_user_name }}"
  107. group: "{{ matrix_group_name }}"
  108. register: matrix_mautrix_googlechat_registration_result
  109. - name: Ensure mautrix-googlechat support files installed
  110. ansible.builtin.template:
  111. src: "{{ role_path }}/templates/{{ item }}.j2"
  112. dest: "{{ matrix_mautrix_googlechat_base_path }}/{{ item }}"
  113. mode: '0640'
  114. owner: "{{ matrix_user_name }}"
  115. group: "{{ matrix_group_name }}"
  116. with_items:
  117. - labels
  118. register: matrix_mautrix_googlechat_support_files_result
  119. - name: Ensure matrix-mautrix-googlechat container network is created
  120. community.general.docker_network:
  121. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  122. name: "{{ matrix_mautrix_googlechat_container_network }}"
  123. driver: bridge
  124. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  125. - name: Ensure matrix-mautrix-googlechat.service installed
  126. ansible.builtin.template:
  127. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  128. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  129. mode: '0644'
  130. register: matrix_mautrix_googlechat_systemd_service_result
  131. - name: Determine whether matrix-mautrix-googlechat needs a restart
  132. ansible.builtin.set_fact:
  133. matrix_mautrix_googlechat_restart_necessary: >-
  134. {{
  135. matrix_mautrix_googlechat_migration_requires_restart | default(false)
  136. or matrix_mautrix_googlechat_config_result.changed | default(false)
  137. or matrix_mautrix_googlechat_registration_result.changed | default(false)
  138. or matrix_mautrix_googlechat_support_files_result.changed | default(false)
  139. or matrix_mautrix_googlechat_systemd_service_result.changed | default(false)
  140. or matrix_mautrix_googlechat_container_image_pull_result.changed | default(false)
  141. or matrix_mautrix_googlechat_container_image_build_result.changed | default(false)
  142. }}
  143. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  144. ansible.builtin.service:
  145. name: "matrix-mautrix-googlechat.service"
  146. state: restarted
  147. daemon_reload: true
  148. when: "matrix_mautrix_googlechat_migration_requires_restart | bool"