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.
 
 

128 regels
5.3 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_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_username }}"
  56. group: "{{ matrix_user_groupname }}"
  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_username }}"
  67. group: "{{ matrix_user_groupname }}"
  68. mode: 0640
  69. - name: Ensure postmoogle image is pulled
  70. community.docker.docker_image:
  71. name: "{{ matrix_postmoogle_docker_image }}"
  72. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  73. force_source: "{{ matrix_postmoogle_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  74. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postmoogle_docker_image_force_pull }}"
  75. when: "not matrix_postmoogle_container_image_self_build | bool"
  76. register: result
  77. retries: "{{ devture_playbook_help_container_retries_count }}"
  78. delay: "{{ devture_playbook_help_container_retries_delay }}"
  79. until: result is not failed
  80. - name: Ensure postmoogle repository is present on self-build
  81. ansible.builtin.git:
  82. repo: "{{ matrix_postmoogle_docker_repo }}"
  83. version: "{{ matrix_postmoogle_docker_repo_version }}"
  84. dest: "{{ matrix_postmoogle_docker_src_files_path }}"
  85. force: "yes"
  86. become: true
  87. become_user: "{{ matrix_user_username }}"
  88. register: matrix_postmoogle_git_pull_results
  89. when: "matrix_postmoogle_container_image_self_build | bool"
  90. - name: Ensure postmoogle image is built
  91. community.docker.docker_image:
  92. name: "{{ matrix_postmoogle_docker_image }}"
  93. source: build
  94. force_source: "{{ matrix_postmoogle_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  95. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postmoogle_git_pull_results.changed }}"
  96. build:
  97. dockerfile: Dockerfile
  98. path: "{{ matrix_postmoogle_docker_src_files_path }}"
  99. pull: true
  100. when: "matrix_postmoogle_container_image_self_build | bool"
  101. - name: Ensure postmoogle container network is created
  102. community.general.docker_network:
  103. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  104. name: "{{ matrix_postmoogle_container_network }}"
  105. driver: bridge
  106. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  107. - name: Ensure matrix-postmoogle.service installed
  108. ansible.builtin.template:
  109. src: "{{ role_path }}/templates/systemd/matrix-postmoogle.service.j2"
  110. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postmoogle.service"
  111. mode: 0644
  112. register: matrix_postmoogle_systemd_service_result