Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

136 lignes
5.6 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. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  66. - name: Ensure Buscarron repository ownership is correct on self-build
  67. ansible.builtin.file:
  68. path: "{{ matrix_bot_buscarron_container_src_files_path }}"
  69. state: directory
  70. owner: "{{ matrix_user_name }}"
  71. group: "{{ matrix_group_name }}"
  72. recurse: true
  73. when: "matrix_bot_buscarron_container_image_self_build | bool"
  74. - name: Ensure Buscarron repository is present on self-build
  75. ansible.builtin.git:
  76. repo: "{{ matrix_bot_buscarron_container_repo }}"
  77. version: "{{ matrix_bot_buscarron_container_repo_version }}"
  78. dest: "{{ matrix_bot_buscarron_container_src_files_path }}"
  79. force: "yes"
  80. become: true
  81. become_user: "{{ matrix_user_name }}"
  82. register: matrix_bot_buscarron_git_pull_results
  83. when: "matrix_bot_buscarron_container_image_self_build | bool"
  84. - name: Ensure Buscarron image is built
  85. community.docker.docker_image_build:
  86. name: "{{ matrix_bot_buscarron_container_image }}"
  87. dockerfile: Dockerfile
  88. path: "{{ matrix_bot_buscarron_container_src_files_path }}"
  89. pull: true
  90. rebuild: "{{ 'always' if matrix_bot_buscarron_git_pull_results.changed | bool else 'never' }}"
  91. when: "matrix_bot_buscarron_container_image_self_build | bool"
  92. register: matrix_bot_buscarron_container_image_build_result
  93. - name: Ensure matrix-bot-buscarron.service installed
  94. ansible.builtin.template:
  95. src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2"
  96. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-buscarron.service"
  97. mode: '0644'
  98. register: matrix_bot_buscarron_systemd_service_result
  99. - name: Determine whether Buscarron needs a restart
  100. ansible.builtin.set_fact:
  101. matrix_bot_buscarron_restart_necessary: >-
  102. {{
  103. matrix_bot_buscarron_migration_requires_restart | default(false)
  104. or matrix_bot_buscarron_support_files_result.changed | default(false)
  105. or matrix_bot_buscarron_systemd_service_result.changed | default(false)
  106. or matrix_bot_buscarron_container_image_pull_result.changed | default(false)
  107. or matrix_bot_buscarron_container_image_build_result.changed | default(false)
  108. }}
  109. - name: Ensure Buscarron container network is created
  110. when: matrix_bot_buscarron_container_network != 'host'
  111. community.general.docker_network:
  112. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  113. name: "{{ matrix_bot_buscarron_container_network }}"
  114. driver: bridge
  115. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  116. - name: Ensure matrix-bot-buscarron.service restarted, if necessary
  117. ansible.builtin.service:
  118. name: "matrix-bot-buscarron.service"
  119. state: restarted
  120. daemon_reload: true
  121. when: "matrix_bot_buscarron_migration_requires_restart | bool"