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

125 строки
5.3 KiB

  1. # SPDX-FileCopyrightText: 2025 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2026 MDAD project contributors
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - name: Ensure Commet paths exist
  7. ansible.builtin.file:
  8. path: "{{ item }}"
  9. state: directory
  10. mode: "0750"
  11. owner: "{{ matrix_user_name }}"
  12. group: "{{ matrix_group_name }}"
  13. with_items:
  14. - "{{ matrix_client_commet_base_path }}"
  15. - "{{ matrix_client_commet_config_path }}"
  16. - name: Ensure Commet container image is pulled
  17. community.docker.docker_image:
  18. name: "{{ matrix_client_commet_container_image }}"
  19. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  20. force_source: "{{ matrix_client_commet_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  21. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_client_commet_container_image_force_pull }}"
  22. when: "not matrix_client_commet_container_image_self_build | bool"
  23. register: matrix_client_commet_image_pull_result
  24. retries: "{{ devture_playbook_help_container_retries_count }}"
  25. delay: "{{ devture_playbook_help_container_retries_delay }}"
  26. until: matrix_client_commet_image_pull_result is not failed
  27. - when: "matrix_client_commet_container_image_self_build | bool"
  28. block:
  29. - name: Check Commet git remote configuration
  30. ansible.builtin.command:
  31. cmd: git -C "{{ matrix_client_commet_container_src_path }}" remote get-url origin
  32. register: matrix_client_commet_git_remote_check
  33. failed_when: false
  34. changed_when: false
  35. - name: Remove Commet source directory if git remote is misconfigured
  36. ansible.builtin.file:
  37. path: "{{ matrix_client_commet_container_src_path }}"
  38. state: absent
  39. when: matrix_client_commet_git_remote_check.rc != 0
  40. become: true
  41. - name: Ensure Commet repository is present on self-build
  42. ansible.builtin.git:
  43. repo: "{{ matrix_client_commet_container_image_self_build_repo }}"
  44. dest: "{{ matrix_client_commet_container_src_path }}"
  45. version: "{{ matrix_client_commet_version }}"
  46. force: "yes"
  47. become: true
  48. become_user: "{{ matrix_user_name }}"
  49. register: matrix_client_commet_git_pull_results
  50. - name: Capture git hash
  51. ansible.builtin.command:
  52. cmd: git -C {{ matrix_client_commet_container_src_path }} rev-parse --short HEAD
  53. register: matrix_client_commet_git_hash_result
  54. changed_when: false
  55. - name: Set git hash fact
  56. ansible.builtin.set_fact:
  57. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_hash_result.stdout | trim }}"
  58. - name: Ensure Commet container image is built
  59. ansible.builtin.command:
  60. cmd: |-
  61. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  62. --tag={{ matrix_client_commet_container_image }}
  63. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  64. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  65. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  66. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  67. {{ matrix_client_commet_container_src_path }}
  68. changed_when: true
  69. register: matrix_client_commet_image_build_result
  70. - name: Ensure Commet global_config.json is installed
  71. ansible.builtin.template:
  72. src: "{{ role_path }}/templates/global_config.json.j2"
  73. dest: "{{ matrix_client_commet_config_path }}/global_config.json"
  74. mode: "0644"
  75. owner: "{{ matrix_user_name }}"
  76. group: "{{ matrix_group_name }}"
  77. register: matrix_client_commet_config_result
  78. - name: Ensure Commet support files are installed
  79. ansible.builtin.template:
  80. src: "{{ item.src }}"
  81. dest: "{{ matrix_client_commet_base_path }}/{{ item.name }}"
  82. mode: "0644"
  83. owner: "{{ matrix_user_name }}"
  84. group: "{{ matrix_group_name }}"
  85. with_items:
  86. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  87. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  88. register: matrix_client_commet_support_files_result
  89. - name: Ensure Commet container network is created
  90. community.general.docker_network:
  91. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  92. name: "{{ matrix_client_commet_container_network }}"
  93. driver: bridge
  94. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  95. - name: Ensure matrix-client-commet.service is installed
  96. ansible.builtin.template:
  97. src: "{{ role_path }}/templates/systemd/matrix-client-commet.service.j2"
  98. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-commet.service"
  99. mode: "0644"
  100. register: matrix_client_commet_systemd_service_result
  101. - name: Determine whether Commet needs a restart
  102. ansible.builtin.set_fact:
  103. matrix_client_commet_restart_necessary: >-
  104. {{
  105. matrix_client_commet_config_result.changed | default(false)
  106. or matrix_client_commet_support_files_result.changed | default(false)
  107. or matrix_client_commet_systemd_service_result.changed | default(false)
  108. or matrix_client_commet_image_build_result.changed | default(false)
  109. or matrix_client_commet_image_pull_result.changed | default(false)
  110. }}