Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

132 строки
6.8 KiB

  1. # SPDX-FileCopyrightText: 2024 David Mehren
  2. # SPDX-FileCopyrightText: 2024 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2024 Catalan Lover <catalanlover@protonmail.com>
  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_appservice_draupnir_for_all_migration_requires_restart: false
  11. - name: Ensure matrix-appservice-draupnir-for-all 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_appservice_draupnir_for_all_base_path }}", when: true}
  20. - {path: "{{ matrix_appservice_draupnir_for_all_config_path }}", when: true}
  21. - {path: "{{ matrix_appservice_draupnir_for_all_data_path }}", when: true}
  22. - {path: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}", when: "{{ matrix_appservice_draupnir_for_all_container_image_self_build }}"}
  23. when: "item.when | bool"
  24. - name: Ensure Draupnir Docker image is pulled
  25. community.docker.docker_image:
  26. name: "{{ matrix_appservice_draupnir_for_all_container_image }}"
  27. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  28. force_source: "{{ matrix_appservice_draupnir_for_all_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  29. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_draupnir_for_all_container_image_force_pull }}"
  30. when: "not matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  31. register: matrix_appservice_draupnir_for_all_container_image_pull_result
  32. retries: "{{ devture_playbook_help_container_retries_count }}"
  33. delay: "{{ devture_playbook_help_container_retries_delay }}"
  34. until: matrix_appservice_draupnir_for_all_container_image_pull_result is not failed
  35. - name: Ensure Draupnir repository is present on self-build
  36. ansible.builtin.git:
  37. repo: "{{ matrix_appservice_draupnir_for_all_container_image_self_build_repo }}"
  38. dest: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}"
  39. version: "{{ matrix_appservice_draupnir_for_all_container_image.split(':')[1] }}"
  40. force: "yes"
  41. become: true
  42. become_user: "{{ matrix_user_name }}"
  43. register: matrix_appservice_draupnir_for_all_git_pull_results
  44. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  45. - name: Ensure Draupnir Docker image is built
  46. community.docker.docker_image:
  47. name: "{{ matrix_appservice_draupnir_for_all_container_image }}"
  48. source: build
  49. force_source: "{{ matrix_appservice_draupnir_for_all_git_pull_results.changed }}"
  50. build:
  51. dockerfile: Dockerfile
  52. path: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}"
  53. pull: true
  54. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  55. - name: Ensure matrix-appservice-draupnir-for-all appservice config installed
  56. ansible.builtin.copy:
  57. content: "{{ matrix_appservice_draupnir_for_all_configuration_appservice | to_nice_yaml(indent=2, width=999999) }}"
  58. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-appservice.yaml"
  59. mode: '0644'
  60. owner: "{{ matrix_user_name }}"
  61. group: "{{ matrix_group_name }}"
  62. register: matrix_appservice_draupnir_for_all_appservice_config_result
  63. - name: Ensure matrix-appservice-draupnir-for-all bot config installed
  64. ansible.builtin.copy:
  65. content: "{{ matrix_appservice_draupnir_for_all_configuration | to_nice_yaml(indent=2, width=999999) }}"
  66. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-bots.yaml"
  67. mode: '0644'
  68. owner: "{{ matrix_user_name }}"
  69. group: "{{ matrix_group_name }}"
  70. register: matrix_appservice_draupnir_for_all_bot_config_result
  71. - name: Ensure matrix-appservice-draupnir-for-all registration.yaml installed
  72. ansible.builtin.copy:
  73. content: "{{ matrix_appservice_draupnir_for_all_registration | to_nice_yaml(indent=2, width=999999) }}"
  74. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/draupnir-for-all-registration.yaml"
  75. mode: '0644'
  76. owner: "{{ matrix_user_name }}"
  77. group: "{{ matrix_group_name }}"
  78. register: matrix_appservice_draupnir_for_all_registration_config_result
  79. - name: Ensure matrix-appservice-draupnir-for-all container network is created
  80. community.general.docker_network:
  81. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  82. name: "{{ matrix_appservice_draupnir_for_all_container_network }}"
  83. driver: bridge
  84. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  85. - name: Ensure matrix-appservice-draupnir-for-all.service installed
  86. ansible.builtin.template:
  87. src: "{{ role_path }}/templates/systemd/matrix-appservice-draupnir-for-all.service.j2"
  88. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-draupnir-for-all.service"
  89. mode: '0644'
  90. register: matrix_appservice_draupnir_for_all_systemd_service_result
  91. # matrix-appservice-draupnir-for-all and matrix-bot-draupnir share the
  92. # same upstream container image. When both are enabled and force-pull is
  93. # on, the second role to run sees the image as already up-to-date (the
  94. # first role just pulled it), so its pull_result.changed is false and
  95. # conditional restart would skip it. To avoid that, we also treat
  96. # force-pull itself as a restart trigger for this role. The downside is
  97. # that both Draupnir services restart on every run when force-pull is
  98. # enabled (e.g. with rolling tags like `latest` or `main`), even when the
  99. # upstream image has not moved. That is wasteful but acceptable.
  100. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5186
  101. - name: Determine whether Draupnir for All needs a restart
  102. ansible.builtin.set_fact:
  103. matrix_appservice_draupnir_for_all_restart_necessary: >-
  104. {{
  105. matrix_appservice_draupnir_for_all_migration_requires_restart | default(false)
  106. or matrix_appservice_draupnir_for_all_appservice_config_result.changed | default(false)
  107. or matrix_appservice_draupnir_for_all_bot_config_result.changed | default(false)
  108. or matrix_appservice_draupnir_for_all_registration_config_result.changed | default(false)
  109. or matrix_appservice_draupnir_for_all_systemd_service_result.changed | default(false)
  110. or matrix_appservice_draupnir_for_all_container_image_pull_result.changed | default(false)
  111. or matrix_appservice_draupnir_for_all_container_image_force_pull | bool
  112. }}
  113. - name: Ensure matrix-appservice-draupnir-for-all.service restarted, if necessary
  114. ansible.builtin.service:
  115. name: "matrix-appservice-draupnir-for-all.service"
  116. state: restarted
  117. daemon_reload: true
  118. when: "matrix_appservice_draupnir_for_all_migration_requires_restart | bool"