Matrix Docker Ansible eploy
Não pode escolher mais do que 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.
 
 

114 linhas
4.8 KiB

  1. # SPDX-FileCopyrightText: 2023 - 2024 MDAD project contributors
  2. # SPDX-FileCopyrightText: 2023 Catalan Lover <catalanlover@protonmail.com>
  3. # SPDX-FileCopyrightText: 2024 David Mehren
  4. # SPDX-FileCopyrightText: 2024 Slavi Pantaleev
  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_draupnir_migration_requires_restart: false
  11. - name: Ensure matrix-bot-draupnir paths exist
  12. ansible.builtin.file:
  13. path: "{{ item.path }}"
  14. state: directory
  15. mode: '0750'
  16. owner: "{{ matrix_user_name }}"
  17. group: "{{ matrix_group_name }}"
  18. with_items:
  19. - {path: "{{ matrix_bot_draupnir_base_path }}", when: true}
  20. - {path: "{{ matrix_bot_draupnir_config_path }}", when: true}
  21. - {path: "{{ matrix_bot_draupnir_data_path }}", when: true}
  22. - {path: "{{ matrix_bot_draupnir_docker_src_files_path }}", when: "{{ matrix_bot_draupnir_container_image_self_build }}"}
  23. when: "item.when | bool"
  24. - name: Ensure matrix-bot-draupnir support files installed
  25. ansible.builtin.template:
  26. src: "{{ item.src }}"
  27. dest: "{{ item.dest }}"
  28. owner: "{{ matrix_user_name }}"
  29. group: "{{ matrix_group_name }}"
  30. mode: '0644'
  31. with_items:
  32. - src: "{{ role_path }}/templates/labels.j2"
  33. dest: "{{ matrix_bot_draupnir_base_path }}/labels"
  34. register: matrix_bot_draupnir_support_files_result
  35. - name: Ensure Draupnir Docker image is pulled
  36. community.docker.docker_image:
  37. name: "{{ matrix_bot_draupnir_docker_image }}"
  38. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  39. force_source: "{{ matrix_bot_draupnir_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  40. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_draupnir_docker_image_force_pull }}"
  41. when: "not matrix_bot_draupnir_container_image_self_build | bool"
  42. register: matrix_bot_draupnir_container_image_pull_result
  43. retries: "{{ devture_playbook_help_container_retries_count }}"
  44. delay: "{{ devture_playbook_help_container_retries_delay }}"
  45. until: matrix_bot_draupnir_container_image_pull_result is not failed
  46. - name: Ensure Draupnir repository is present on self-build
  47. ansible.builtin.git:
  48. repo: "{{ matrix_bot_draupnir_container_image_self_build_repo }}"
  49. dest: "{{ matrix_bot_draupnir_docker_src_files_path }}"
  50. version: "{{ matrix_bot_draupnir_docker_image.split(':')[1] }}"
  51. force: "yes"
  52. become: true
  53. become_user: "{{ matrix_user_name }}"
  54. register: matrix_bot_draupnir_git_pull_results
  55. when: "matrix_bot_draupnir_container_image_self_build | bool"
  56. - name: Ensure Draupnir Docker image is built
  57. community.docker.docker_image:
  58. name: "{{ matrix_bot_draupnir_docker_image }}"
  59. source: build
  60. force_source: "{{ matrix_bot_draupnir_git_pull_results.changed }}"
  61. build:
  62. dockerfile: Dockerfile
  63. path: "{{ matrix_bot_draupnir_docker_src_files_path }}"
  64. pull: true
  65. when: "matrix_bot_draupnir_container_image_self_build | bool"
  66. - name: Ensure matrix-bot-draupnir config installed
  67. ansible.builtin.copy:
  68. content: "{{ matrix_bot_draupnir_configuration | to_nice_yaml(indent=2, width=999999) }}"
  69. dest: "{{ matrix_bot_draupnir_config_path }}/production.yaml"
  70. mode: '0644'
  71. owner: "{{ matrix_user_name }}"
  72. group: "{{ matrix_group_name }}"
  73. register: matrix_bot_draupnir_config_result
  74. - name: Ensure matrix-bot-draupnir container network is created
  75. community.general.docker_network:
  76. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  77. name: "{{ matrix_bot_draupnir_container_network }}"
  78. driver: bridge
  79. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  80. - name: Ensure matrix-bot-draupnir.service installed
  81. ansible.builtin.template:
  82. src: "{{ role_path }}/templates/systemd/matrix-bot-draupnir.service.j2"
  83. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-draupnir.service"
  84. mode: '0644'
  85. register: matrix_bot_draupnir_systemd_service_result
  86. - name: Determine whether Draupnir needs a restart
  87. ansible.builtin.set_fact:
  88. matrix_bot_draupnir_restart_necessary: >-
  89. {{
  90. matrix_bot_draupnir_migration_requires_restart | default(false)
  91. or matrix_bot_draupnir_support_files_result.changed | default(false)
  92. or matrix_bot_draupnir_config_result.changed | default(false)
  93. or matrix_bot_draupnir_systemd_service_result.changed | default(false)
  94. or matrix_bot_draupnir_container_image_pull_result.changed | default(false)
  95. }}
  96. - name: Ensure matrix-bot-draupnir.service restarted, if necessary
  97. ansible.builtin.service:
  98. name: "matrix-bot-draupnir.service"
  99. state: restarted
  100. daemon_reload: true
  101. when: "matrix_bot_draupnir_migration_requires_restart | bool"