Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

149 lines
6.5 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - ansible.builtin.set_fact:
  6. matrix_mautrix_googlechat_requires_restart: false
  7. - when: "matrix_mautrix_googlechat_database_engine == 'postgres'"
  8. block:
  9. - name: Check if an SQLite database already exists
  10. ansible.builtin.stat:
  11. path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  12. register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result
  13. - when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists | bool"
  14. block:
  15. - ansible.builtin.include_role:
  16. name: galaxy/postgres
  17. tasks_from: migrate_db_to_postgres
  18. vars:
  19. postgres_db_migration_request:
  20. src: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  21. dst: "{{ matrix_mautrix_googlechat_database_connection_string }}"
  22. caller: "{{ role_path | basename }}"
  23. engine_variable_name: 'matrix_mautrix_googlechat_database_engine'
  24. engine_old: 'sqlite'
  25. systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
  26. - ansible.builtin.set_fact:
  27. matrix_mautrix_googlechat_requires_restart: true
  28. - name: Ensure Mautrix googlechat image is pulled
  29. community.docker.docker_image:
  30. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  31. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  32. force_source: "{{ matrix_mautrix_googlechat_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  33. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_docker_image_force_pull }}"
  34. when: not matrix_mautrix_googlechat_container_image_self_build
  35. register: result
  36. retries: "{{ devture_playbook_help_container_retries_count }}"
  37. delay: "{{ devture_playbook_help_container_retries_delay }}"
  38. until: result is not failed
  39. - name: Ensure Mautrix googlechat paths exist
  40. ansible.builtin.file:
  41. path: "{{ item.path }}"
  42. state: directory
  43. mode: 0750
  44. owner: "{{ matrix_user_username }}"
  45. group: "{{ matrix_user_groupname }}"
  46. with_items:
  47. - {path: "{{ matrix_mautrix_googlechat_base_path }}", when: true}
  48. - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true}
  49. - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true}
  50. - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"}
  51. when: "item.when | bool"
  52. - name: Ensure Mautrix Hangots repository is present on self build
  53. ansible.builtin.git:
  54. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  55. version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}"
  56. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  57. force: "yes"
  58. become: true
  59. become_user: "{{ matrix_user_username }}"
  60. register: matrix_mautrix_googlechat_git_pull_results
  61. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  62. - name: Ensure Mautrix googlechat Docker image is built
  63. community.docker.docker_image:
  64. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  65. source: build
  66. force_source: "{{ matrix_mautrix_googlechat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  67. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_git_pull_results.changed }}"
  68. build:
  69. dockerfile: Dockerfile
  70. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  71. pull: true
  72. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  73. - name: Check if an old database file already exists
  74. ansible.builtin.stat:
  75. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  76. register: matrix_mautrix_googlechat_stat_database
  77. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  78. ansible.builtin.service:
  79. name: matrix-mautrix-googlechat
  80. state: stopped
  81. enabled: false
  82. daemon_reload: true
  83. failed_when: false
  84. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  85. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  86. ansible.builtin.command:
  87. cmd: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  88. creates: "{{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  89. removes: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  90. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  91. - name: Ensure mautrix-googlechat config.yaml installed
  92. ansible.builtin.copy:
  93. content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  94. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  95. mode: 0644
  96. owner: "{{ matrix_user_username }}"
  97. group: "{{ matrix_user_groupname }}"
  98. - name: Ensure mautrix-googlechat registration.yaml installed
  99. ansible.builtin.copy:
  100. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  101. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  102. mode: 0644
  103. owner: "{{ matrix_user_username }}"
  104. group: "{{ matrix_user_groupname }}"
  105. - name: Ensure mautrix-googlechat support files installed
  106. ansible.builtin.template:
  107. src: "{{ role_path }}/templates/{{ item }}.j2"
  108. dest: "{{ matrix_mautrix_googlechat_base_path }}/{{ item }}"
  109. mode: 0640
  110. owner: "{{ matrix_user_username }}"
  111. group: "{{ matrix_user_groupname }}"
  112. with_items:
  113. - labels
  114. - name: Ensure matrix-mautrix-googlechat container network is created
  115. community.general.docker_network:
  116. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  117. name: "{{ matrix_mautrix_googlechat_container_network }}"
  118. driver: bridge
  119. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  120. - name: Ensure matrix-mautrix-googlechat.service installed
  121. ansible.builtin.template:
  122. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  123. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  124. mode: 0644
  125. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  126. ansible.builtin.service:
  127. name: "matrix-mautrix-googlechat.service"
  128. state: restarted
  129. daemon_reload: true
  130. when: "matrix_mautrix_googlechat_requires_restart | bool"