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.
 
 

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