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

125 строки
5.1 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2023 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  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. - ansible.builtin.set_fact:
  10. matrix_bot_buscarron_migration_requires_restart: false
  11. - when: "matrix_bot_buscarron_database_engine == 'postgres'"
  12. block:
  13. - name: Check if an SQLite database already exists
  14. ansible.builtin.stat:
  15. path: "{{ matrix_bot_buscarron_sqlite_database_path_local }}"
  16. register: matrix_bot_buscarron_sqlite_database_path_local_stat_result
  17. - when: "matrix_bot_buscarron_sqlite_database_path_local_stat_result.stat.exists | bool"
  18. block:
  19. - ansible.builtin.include_role:
  20. name: galaxy/postgres
  21. tasks_from: migrate_db_to_postgres
  22. vars:
  23. postgres_db_migration_request:
  24. src: "{{ matrix_bot_buscarron_sqlite_database_path_local }}"
  25. dst: "{{ matrix_bot_buscarron_database_connection_string }}"
  26. caller: "{{ role_path | basename }}"
  27. engine_variable_name: 'matrix_bot_buscarron_database_engine'
  28. engine_old: 'sqlite'
  29. systemd_services_to_stop: ['matrix-bot-buscarron.service']
  30. - ansible.builtin.set_fact:
  31. matrix_bot_buscarron_migration_requires_restart: true
  32. - name: Ensure Buscarron paths exist
  33. ansible.builtin.file:
  34. path: "{{ item.path }}"
  35. state: directory
  36. mode: '0750'
  37. owner: "{{ matrix_user_name }}"
  38. group: "{{ matrix_group_name }}"
  39. with_items:
  40. - {path: "{{ matrix_bot_buscarron_config_path }}", when: true}
  41. - {path: "{{ matrix_bot_buscarron_data_path }}", when: true}
  42. - {path: "{{ matrix_bot_buscarron_data_store_path }}", when: true}
  43. - {path: "{{ matrix_bot_buscarron_container_src_files_path }}", when: true}
  44. when: "item.when | bool"
  45. - name: Ensure Buscarron support files installed
  46. ansible.builtin.template:
  47. src: "{{ role_path }}/templates/{{ item }}.j2"
  48. dest: "{{ matrix_bot_buscarron_config_path }}/{{ item }}"
  49. owner: "{{ matrix_user_name }}"
  50. group: "{{ matrix_group_name }}"
  51. mode: '0640'
  52. with_items:
  53. - env
  54. - labels
  55. register: matrix_bot_buscarron_support_files_result
  56. - name: Ensure Buscarron image is pulled
  57. community.docker.docker_image_pull:
  58. name: "{{ matrix_bot_buscarron_container_image }}"
  59. pull: always
  60. when: "not matrix_bot_buscarron_container_image_self_build | bool"
  61. register: matrix_bot_buscarron_container_image_pull_result
  62. retries: "{{ devture_playbook_help_container_retries_count }}"
  63. delay: "{{ devture_playbook_help_container_retries_delay }}"
  64. until: matrix_bot_buscarron_container_image_pull_result is not failed
  65. - name: Ensure Buscarron repository is present on self-build
  66. ansible.builtin.git:
  67. repo: "{{ matrix_bot_buscarron_container_repo }}"
  68. version: "{{ matrix_bot_buscarron_container_repo_version }}"
  69. dest: "{{ matrix_bot_buscarron_container_src_files_path }}"
  70. force: "yes"
  71. become: true
  72. become_user: "{{ matrix_user_name }}"
  73. register: matrix_bot_buscarron_git_pull_results
  74. when: "matrix_bot_buscarron_container_image_self_build | bool"
  75. - name: Ensure Buscarron image is built
  76. community.docker.docker_image_build:
  77. name: "{{ matrix_bot_buscarron_container_image }}"
  78. dockerfile: Dockerfile
  79. path: "{{ matrix_bot_buscarron_container_src_files_path }}"
  80. pull: true
  81. rebuild: "{{ 'always' if matrix_bot_buscarron_git_pull_results.changed | bool else 'never' }}"
  82. when: "matrix_bot_buscarron_container_image_self_build | bool"
  83. register: matrix_bot_buscarron_container_image_build_result
  84. - name: Ensure matrix-bot-buscarron.service installed
  85. ansible.builtin.template:
  86. src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2"
  87. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-buscarron.service"
  88. mode: '0644'
  89. register: matrix_bot_buscarron_systemd_service_result
  90. - name: Determine whether Buscarron needs a restart
  91. ansible.builtin.set_fact:
  92. matrix_bot_buscarron_restart_necessary: >-
  93. {{
  94. matrix_bot_buscarron_migration_requires_restart | default(false)
  95. or matrix_bot_buscarron_support_files_result.changed | default(false)
  96. or matrix_bot_buscarron_systemd_service_result.changed | default(false)
  97. or matrix_bot_buscarron_container_image_pull_result.changed | default(false)
  98. or matrix_bot_buscarron_container_image_build_result.changed | default(false)
  99. }}
  100. - name: Ensure Buscarron container network is created
  101. community.general.docker_network:
  102. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  103. name: "{{ matrix_bot_buscarron_container_network }}"
  104. driver: bridge
  105. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  106. - name: Ensure matrix-bot-buscarron.service restarted, if necessary
  107. ansible.builtin.service:
  108. name: "matrix-bot-buscarron.service"
  109. state: restarted
  110. daemon_reload: true
  111. when: "matrix_bot_buscarron_migration_requires_restart | bool"