Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

171 lignes
7.8 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:
  36. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  37. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  38. force_source: "{{ matrix_mautrix_googlechat_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  39. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_docker_image_force_pull }}"
  40. when: not matrix_mautrix_googlechat_container_image_self_build
  41. register: matrix_mautrix_googlechat_container_image_pull_result
  42. retries: "{{ devture_playbook_help_container_retries_count }}"
  43. delay: "{{ devture_playbook_help_container_retries_delay }}"
  44. until: matrix_mautrix_googlechat_container_image_pull_result is not failed
  45. - name: Ensure Mautrix googlechat paths exist
  46. ansible.builtin.file:
  47. path: "{{ item.path }}"
  48. state: directory
  49. mode: '0750'
  50. owner: "{{ matrix_user_name }}"
  51. group: "{{ matrix_group_name }}"
  52. with_items:
  53. - {path: "{{ matrix_mautrix_googlechat_base_path }}", when: true}
  54. - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true}
  55. - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true}
  56. - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"}
  57. when: "item.when | bool"
  58. - name: Ensure Mautrix Hangots repository is present on self build
  59. ansible.builtin.git:
  60. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  61. version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}"
  62. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  63. force: "yes"
  64. become: true
  65. become_user: "{{ matrix_user_name }}"
  66. register: matrix_mautrix_googlechat_git_pull_results
  67. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  68. - name: Ensure Mautrix googlechat Docker image is built
  69. community.docker.docker_image:
  70. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  71. source: build
  72. force_source: "{{ matrix_mautrix_googlechat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  73. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_git_pull_results.changed }}"
  74. build:
  75. dockerfile: Dockerfile
  76. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  77. pull: true
  78. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  79. - name: Check if an old database file already exists
  80. ansible.builtin.stat:
  81. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  82. register: matrix_mautrix_googlechat_stat_database
  83. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  84. ansible.builtin.service:
  85. name: matrix-mautrix-googlechat
  86. state: stopped
  87. enabled: false
  88. daemon_reload: true
  89. failed_when: false
  90. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  91. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  92. ansible.builtin.command:
  93. cmd: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  94. creates: "{{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  95. removes: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  96. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  97. - name: Ensure mautrix-googlechat config.yaml installed
  98. ansible.builtin.copy:
  99. content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  100. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  101. mode: '0644'
  102. owner: "{{ matrix_user_name }}"
  103. group: "{{ matrix_group_name }}"
  104. register: matrix_mautrix_googlechat_config_result
  105. - name: Ensure mautrix-googlechat registration.yaml installed
  106. ansible.builtin.copy:
  107. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  108. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  109. mode: '0644'
  110. owner: "{{ matrix_user_name }}"
  111. group: "{{ matrix_group_name }}"
  112. register: matrix_mautrix_googlechat_registration_result
  113. - name: Ensure mautrix-googlechat support files installed
  114. ansible.builtin.template:
  115. src: "{{ role_path }}/templates/{{ item }}.j2"
  116. dest: "{{ matrix_mautrix_googlechat_base_path }}/{{ item }}"
  117. mode: '0640'
  118. owner: "{{ matrix_user_name }}"
  119. group: "{{ matrix_group_name }}"
  120. with_items:
  121. - labels
  122. register: matrix_mautrix_googlechat_support_files_result
  123. - name: Ensure matrix-mautrix-googlechat container network is created
  124. community.general.docker_network:
  125. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  126. name: "{{ matrix_mautrix_googlechat_container_network }}"
  127. driver: bridge
  128. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  129. - name: Ensure matrix-mautrix-googlechat.service installed
  130. ansible.builtin.template:
  131. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  132. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  133. mode: '0644'
  134. register: matrix_mautrix_googlechat_systemd_service_result
  135. - name: Determine whether matrix-mautrix-googlechat needs a restart
  136. ansible.builtin.set_fact:
  137. matrix_mautrix_googlechat_restart_necessary: >-
  138. {{
  139. matrix_mautrix_googlechat_migration_requires_restart | default(false)
  140. or matrix_mautrix_googlechat_config_result.changed | default(false)
  141. or matrix_mautrix_googlechat_registration_result.changed | default(false)
  142. or matrix_mautrix_googlechat_support_files_result.changed | default(false)
  143. or matrix_mautrix_googlechat_systemd_service_result.changed | default(false)
  144. or matrix_mautrix_googlechat_container_image_pull_result.changed | default(false)
  145. }}
  146. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  147. ansible.builtin.service:
  148. name: "matrix-mautrix-googlechat.service"
  149. state: restarted
  150. daemon_reload: true
  151. when: "matrix_mautrix_googlechat_migration_requires_restart | bool"