Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

124 righe
5.2 KiB

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