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

127 строки
5.1 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  3. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  6. # SPDX-FileCopyrightText: 2024 David Mehren
  7. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - ansible.builtin.set_fact:
  12. matrix_bot_honoroit_migration_requires_restart: false
  13. - when: "matrix_bot_honoroit_database_engine == 'postgres'"
  14. block:
  15. - name: Check if an SQLite database already exists
  16. ansible.builtin.stat:
  17. path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  18. register: matrix_bot_honoroit_sqlite_database_path_local_stat_result
  19. - when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists | bool"
  20. block:
  21. - ansible.builtin.include_role:
  22. name: galaxy/postgres
  23. tasks_from: migrate_db_to_postgres
  24. vars:
  25. postgres_db_migration_request:
  26. src: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  27. dst: "{{ matrix_bot_honoroit_database_connection_string }}"
  28. caller: "{{ role_path | basename }}"
  29. engine_variable_name: 'matrix_bot_honoroit_database_engine'
  30. engine_old: 'sqlite'
  31. systemd_services_to_stop: ['matrix-bot-honoroit.service']
  32. - ansible.builtin.set_fact:
  33. matrix_bot_honoroit_migration_requires_restart: true
  34. - name: Ensure Honoroit paths exist
  35. ansible.builtin.file:
  36. path: "{{ item.path }}"
  37. state: directory
  38. mode: '0750'
  39. owner: "{{ matrix_user_name }}"
  40. group: "{{ matrix_group_name }}"
  41. with_items:
  42. - {path: "{{ matrix_bot_honoroit_config_path }}", when: true}
  43. - {path: "{{ matrix_bot_honoroit_data_path }}", when: true}
  44. - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true}
  45. - {path: "{{ matrix_bot_honoroit_container_src_files_path }}", when: true}
  46. when: "item.when | bool"
  47. - name: Ensure Honoroit support files installed
  48. ansible.builtin.template:
  49. src: "{{ role_path }}/templates/{{ item }}.j2"
  50. dest: "{{ matrix_bot_honoroit_config_path }}/{{ item }}"
  51. owner: "{{ matrix_user_name }}"
  52. group: "{{ matrix_group_name }}"
  53. mode: '0640'
  54. with_items:
  55. - env
  56. - labels
  57. register: matrix_bot_honoroit_support_files_result
  58. - name: Ensure Honoroit image is pulled
  59. community.docker.docker_image_pull:
  60. name: "{{ matrix_bot_honoroit_container_image }}"
  61. pull: always
  62. when: "not matrix_bot_honoroit_container_image_self_build | bool"
  63. register: matrix_bot_honoroit_container_image_pull_result
  64. retries: "{{ devture_playbook_help_container_retries_count }}"
  65. delay: "{{ devture_playbook_help_container_retries_delay }}"
  66. until: matrix_bot_honoroit_container_image_pull_result is not failed
  67. - name: Ensure Honoroit repository is present on self-build
  68. ansible.builtin.git:
  69. repo: "{{ matrix_bot_honoroit_container_repo }}"
  70. version: "{{ matrix_bot_honoroit_container_repo_version }}"
  71. dest: "{{ matrix_bot_honoroit_container_src_files_path }}"
  72. force: "yes"
  73. become: true
  74. become_user: "{{ matrix_user_name }}"
  75. register: matrix_bot_honoroit_git_pull_results
  76. when: "matrix_bot_honoroit_container_image_self_build | bool"
  77. - name: Ensure Honoroit image is built
  78. community.docker.docker_image_build:
  79. name: "{{ matrix_bot_honoroit_container_image }}"
  80. dockerfile: Dockerfile
  81. path: "{{ matrix_bot_honoroit_container_src_files_path }}"
  82. pull: true
  83. rebuild: "{{ 'always' if matrix_bot_honoroit_git_pull_results.changed | bool else 'never' }}"
  84. when: "matrix_bot_honoroit_container_image_self_build | bool"
  85. register: matrix_bot_honoroit_container_image_build_result
  86. - name: Ensure Honoroit container network is created
  87. community.general.docker_network:
  88. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  89. name: "{{ matrix_bot_honoroit_container_network }}"
  90. driver: bridge
  91. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  92. - name: Ensure matrix-bot-honoroit.service installed
  93. ansible.builtin.template:
  94. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  95. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-honoroit.service"
  96. mode: '0644'
  97. register: matrix_bot_honoroit_systemd_service_result
  98. - name: Determine whether Honoroit needs a restart
  99. ansible.builtin.set_fact:
  100. matrix_bot_honoroit_restart_necessary: >-
  101. {{
  102. matrix_bot_honoroit_migration_requires_restart | default(false)
  103. or matrix_bot_honoroit_support_files_result.changed | default(false)
  104. or matrix_bot_honoroit_systemd_service_result.changed | default(false)
  105. or matrix_bot_honoroit_container_image_pull_result.changed | default(false)
  106. or matrix_bot_honoroit_container_image_build_result.changed | default(false)
  107. }}
  108. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  109. ansible.builtin.service:
  110. name: "matrix-bot-honoroit.service"
  111. state: restarted
  112. daemon_reload: true
  113. when: "matrix_bot_honoroit_migration_requires_restart | bool"