Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

121 regels
6.0 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. - name: Determine whether Draupnir for All needs a restart
  92. ansible.builtin.set_fact:
  93. matrix_appservice_draupnir_for_all_restart_necessary: >-
  94. {{
  95. matrix_appservice_draupnir_for_all_migration_requires_restart | default(false)
  96. or matrix_appservice_draupnir_for_all_appservice_config_result.changed | default(false)
  97. or matrix_appservice_draupnir_for_all_bot_config_result.changed | default(false)
  98. or matrix_appservice_draupnir_for_all_registration_config_result.changed | default(false)
  99. or matrix_appservice_draupnir_for_all_systemd_service_result.changed | default(false)
  100. or matrix_appservice_draupnir_for_all_container_image_pull_result.changed | default(false)
  101. }}
  102. - name: Ensure matrix-appservice-draupnir-for-all.service restarted, if necessary
  103. ansible.builtin.service:
  104. name: "matrix-appservice-draupnir-for-all.service"
  105. state: restarted
  106. daemon_reload: true
  107. when: "matrix_appservice_draupnir_for_all_migration_requires_restart | bool"