Matrix Docker Ansible eploy
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

125 行
5.5 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_container_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_container_image }}"
  38. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  39. force_source: "{{ matrix_bot_draupnir_container_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_container_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_container_src_files_path }}"
  50. version: "{{ matrix_bot_draupnir_container_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_container_image }}"
  59. source: build
  60. force_source: "{{ matrix_bot_draupnir_git_pull_results.changed }}"
  61. build:
  62. dockerfile: Dockerfile
  63. path: "{{ matrix_bot_draupnir_container_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. # matrix-bot-draupnir and matrix-appservice-draupnir-for-all share the
  87. # same upstream container image. When both are enabled and force-pull is
  88. # on, the second role to run sees the image as already up-to-date (the
  89. # first role just pulled it), so its pull_result.changed is false and
  90. # conditional restart would skip it. To avoid that, we also treat
  91. # force-pull itself as a restart trigger for this role. The downside is
  92. # that both Draupnir services restart on every run when force-pull is
  93. # enabled (e.g. with rolling tags like `latest` or `main`), even when the
  94. # upstream image has not moved. That is wasteful but acceptable.
  95. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5186
  96. - name: Determine whether Draupnir needs a restart
  97. ansible.builtin.set_fact:
  98. matrix_bot_draupnir_restart_necessary: >-
  99. {{
  100. matrix_bot_draupnir_migration_requires_restart | default(false)
  101. or matrix_bot_draupnir_support_files_result.changed | default(false)
  102. or matrix_bot_draupnir_config_result.changed | default(false)
  103. or matrix_bot_draupnir_systemd_service_result.changed | default(false)
  104. or matrix_bot_draupnir_container_image_pull_result.changed | default(false)
  105. or matrix_bot_draupnir_container_image_force_pull | bool
  106. }}
  107. - name: Ensure matrix-bot-draupnir.service restarted, if necessary
  108. ansible.builtin.service:
  109. name: "matrix-bot-draupnir.service"
  110. state: restarted
  111. daemon_reload: true
  112. when: "matrix_bot_draupnir_migration_requires_restart | bool"