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

139 строки
5.9 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  3. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  4. # SPDX-FileCopyrightText: 2024 David Mehren
  5. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  6. #
  7. # SPDX-License-Identifier: AGPL-3.0-or-later
  8. ---
  9. # Check and remove the legacy systemd service (`matrix-bot-postmoogle.service`).
  10. # This role uses `matrix-postmoogle.service` now.
  11. # Related to: https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/3698
  12. - name: Check if matrix-bot-postmoogle.service exists
  13. ansible.builtin.stat:
  14. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-postmoogle.service"
  15. register: matrix_bot_postmoogle_service_stat
  16. - name: Stop and remove legacy matrix-bot-postmoogle systemd service
  17. when: matrix_bot_postmoogle_service_stat.stat.exists | bool
  18. block:
  19. - name: Ensure legacy matrix-bot-postmoogle service is stopped
  20. ansible.builtin.service:
  21. name: matrix-bot-postmoogle
  22. state: stopped
  23. enabled: false
  24. failed_when: false
  25. - name: Remove legacy matrix-bot-postmoogle service file
  26. ansible.builtin.file:
  27. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-postmoogle.service"
  28. state: absent
  29. - when: "matrix_postmoogle_database_engine == 'postgres'"
  30. block:
  31. - name: Check if an SQLite database already exists
  32. ansible.builtin.stat:
  33. path: "{{ matrix_postmoogle_sqlite_database_path_local }}"
  34. register: matrix_postmoogle_sqlite_database_path_local_stat_result
  35. - when: "matrix_postmoogle_sqlite_database_path_local_stat_result.stat.exists | bool"
  36. block:
  37. - ansible.builtin.include_role:
  38. name: galaxy/postgres
  39. tasks_from: migrate_db_to_postgres
  40. vars:
  41. postgres_db_migration_request:
  42. src: "{{ matrix_postmoogle_sqlite_database_path_local }}"
  43. dst: "{{ matrix_postmoogle_database_connection_string }}"
  44. caller: "{{ role_path | basename }}"
  45. engine_variable_name: 'matrix_postmoogle_database_engine'
  46. engine_old: 'sqlite'
  47. systemd_services_to_stop: ['matrix-postmoogle.service']
  48. - ansible.builtin.set_fact:
  49. matrix_postmoogle_migration_requires_restart: true
  50. - name: Ensure postmoogle paths exist
  51. ansible.builtin.file:
  52. path: "{{ item.path }}"
  53. state: directory
  54. mode: '0750'
  55. owner: "{{ matrix_user_name }}"
  56. group: "{{ matrix_group_name }}"
  57. with_items:
  58. - {path: "{{ matrix_postmoogle_config_path }}", when: true}
  59. - {path: "{{ matrix_postmoogle_data_path }}", when: true}
  60. - {path: "{{ matrix_postmoogle_docker_src_files_path }}", when: "{{ matrix_postmoogle_container_image_self_build }}"}
  61. when: "item.when | bool"
  62. - name: Ensure postmoogle environment variables file created
  63. ansible.builtin.template:
  64. src: "{{ role_path }}/templates/env.j2"
  65. dest: "{{ matrix_postmoogle_config_path }}/env"
  66. owner: "{{ matrix_user_name }}"
  67. group: "{{ matrix_group_name }}"
  68. mode: '0640'
  69. register: matrix_postmoogle_env_result
  70. - name: Ensure postmoogle image is pulled
  71. community.docker.docker_image:
  72. name: "{{ matrix_postmoogle_docker_image }}"
  73. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  74. force_source: "{{ matrix_postmoogle_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  75. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postmoogle_docker_image_force_pull }}"
  76. when: "not matrix_postmoogle_container_image_self_build | bool"
  77. register: matrix_postmoogle_container_image_pull_result
  78. retries: "{{ devture_playbook_help_container_retries_count }}"
  79. delay: "{{ devture_playbook_help_container_retries_delay }}"
  80. until: matrix_postmoogle_container_image_pull_result is not failed
  81. - name: Ensure postmoogle repository is present on self-build
  82. ansible.builtin.git:
  83. repo: "{{ matrix_postmoogle_docker_repo }}"
  84. version: "{{ matrix_postmoogle_docker_repo_version }}"
  85. dest: "{{ matrix_postmoogle_docker_src_files_path }}"
  86. force: "yes"
  87. become: true
  88. become_user: "{{ matrix_user_name }}"
  89. register: matrix_postmoogle_git_pull_results
  90. when: "matrix_postmoogle_container_image_self_build | bool"
  91. - name: Ensure postmoogle image is built
  92. community.docker.docker_image:
  93. name: "{{ matrix_postmoogle_docker_image }}"
  94. source: build
  95. force_source: "{{ matrix_postmoogle_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  96. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postmoogle_git_pull_results.changed }}"
  97. build:
  98. dockerfile: Dockerfile
  99. path: "{{ matrix_postmoogle_docker_src_files_path }}"
  100. pull: true
  101. when: "matrix_postmoogle_container_image_self_build | bool"
  102. - name: Ensure postmoogle container network is created
  103. community.general.docker_network:
  104. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  105. name: "{{ matrix_postmoogle_container_network }}"
  106. driver: bridge
  107. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  108. - name: Ensure matrix-postmoogle.service installed
  109. ansible.builtin.template:
  110. src: "{{ role_path }}/templates/systemd/matrix-postmoogle.service.j2"
  111. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postmoogle.service"
  112. mode: '0644'
  113. register: matrix_postmoogle_systemd_service_result
  114. - name: Determine whether matrix-postmoogle needs a restart
  115. ansible.builtin.set_fact:
  116. matrix_postmoogle_restart_necessary: >-
  117. {{
  118. matrix_postmoogle_migration_requires_restart | default(false)
  119. or matrix_postmoogle_env_result.changed | default(false)
  120. or matrix_postmoogle_systemd_service_result.changed | default(false)
  121. or matrix_postmoogle_container_image_pull_result.changed | default(false)
  122. }}