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.
 
 

155 lignes
6.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_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_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: result
  42. retries: "{{ devture_playbook_help_container_retries_count }}"
  43. delay: "{{ devture_playbook_help_container_retries_delay }}"
  44. until: 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. - name: Ensure mautrix-googlechat registration.yaml installed
  105. ansible.builtin.copy:
  106. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  107. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  108. mode: 0644
  109. owner: "{{ matrix_user_name }}"
  110. group: "{{ matrix_group_name }}"
  111. - name: Ensure mautrix-googlechat support files installed
  112. ansible.builtin.template:
  113. src: "{{ role_path }}/templates/{{ item }}.j2"
  114. dest: "{{ matrix_mautrix_googlechat_base_path }}/{{ item }}"
  115. mode: 0640
  116. owner: "{{ matrix_user_name }}"
  117. group: "{{ matrix_group_name }}"
  118. with_items:
  119. - labels
  120. - name: Ensure matrix-mautrix-googlechat container network is created
  121. community.general.docker_network:
  122. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  123. name: "{{ matrix_mautrix_googlechat_container_network }}"
  124. driver: bridge
  125. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  126. - name: Ensure matrix-mautrix-googlechat.service installed
  127. ansible.builtin.template:
  128. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  129. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  130. mode: 0644
  131. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  132. ansible.builtin.service:
  133. name: "matrix-mautrix-googlechat.service"
  134. state: restarted
  135. daemon_reload: true
  136. when: "matrix_mautrix_googlechat_requires_restart | bool"