Matrix Docker Ansible eploy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

130 linhas
5.5 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_docker_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:
  60. name: "{{ matrix_bot_honoroit_docker_image }}"
  61. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  62. force_source: "{{ matrix_bot_honoroit_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  63. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_honoroit_docker_image_force_pull }}"
  64. when: "not matrix_bot_honoroit_container_image_self_build | bool"
  65. register: matrix_bot_honoroit_container_image_pull_result
  66. retries: "{{ devture_playbook_help_container_retries_count }}"
  67. delay: "{{ devture_playbook_help_container_retries_delay }}"
  68. until: matrix_bot_honoroit_container_image_pull_result is not failed
  69. - name: Ensure Honoroit repository is present on self-build
  70. ansible.builtin.git:
  71. repo: "{{ matrix_bot_honoroit_docker_repo }}"
  72. version: "{{ matrix_bot_honoroit_docker_repo_version }}"
  73. dest: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  74. force: "yes"
  75. become: true
  76. become_user: "{{ matrix_user_name }}"
  77. register: matrix_bot_honoroit_git_pull_results
  78. when: "matrix_bot_honoroit_container_image_self_build | bool"
  79. - name: Ensure Honoroit image is built
  80. community.docker.docker_image:
  81. name: "{{ matrix_bot_honoroit_docker_image }}"
  82. source: build
  83. force_source: "{{ matrix_bot_honoroit_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  84. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_honoroit_container_image_self_build.changed }}"
  85. build:
  86. dockerfile: Dockerfile
  87. path: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  88. pull: true
  89. when: "matrix_bot_honoroit_container_image_self_build | bool"
  90. - name: Ensure Honoroit container network is created
  91. community.general.docker_network:
  92. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  93. name: "{{ matrix_bot_honoroit_container_network }}"
  94. driver: bridge
  95. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  96. - name: Ensure matrix-bot-honoroit.service installed
  97. ansible.builtin.template:
  98. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  99. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-honoroit.service"
  100. mode: '0644'
  101. register: matrix_bot_honoroit_systemd_service_result
  102. - name: Determine whether Honoroit needs a restart
  103. ansible.builtin.set_fact:
  104. matrix_bot_honoroit_restart_necessary: >-
  105. {{
  106. matrix_bot_honoroit_migration_requires_restart | default(false)
  107. or matrix_bot_honoroit_support_files_result.changed | default(false)
  108. or matrix_bot_honoroit_systemd_service_result.changed | default(false)
  109. or matrix_bot_honoroit_container_image_pull_result.changed | default(false)
  110. }}
  111. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  112. ansible.builtin.service:
  113. name: "matrix-bot-honoroit.service"
  114. state: restarted
  115. daemon_reload: true
  116. when: "matrix_bot_honoroit_migration_requires_restart | bool"