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

125 строки
5.1 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_pull:
  18. name: "{{ matrix_client_commet_container_image }}"
  19. pull: always
  20. when: "not matrix_client_commet_container_image_self_build | bool"
  21. register: matrix_client_commet_image_pull_result
  22. retries: "{{ devture_playbook_help_container_retries_count }}"
  23. delay: "{{ devture_playbook_help_container_retries_delay }}"
  24. until: matrix_client_commet_image_pull_result is not failed
  25. - when: "matrix_client_commet_container_image_self_build | bool"
  26. block:
  27. - name: Check Commet git repository metadata exists
  28. ansible.builtin.stat:
  29. path: "{{ matrix_client_commet_container_src_path }}/.git/config"
  30. register: matrix_client_commet_git_config_file_stat
  31. - name: Remove Commet source directory if git remote is misconfigured
  32. ansible.builtin.file:
  33. path: "{{ matrix_client_commet_container_src_path }}"
  34. state: absent
  35. when: not matrix_client_commet_git_config_file_stat.stat.exists
  36. become: true
  37. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  38. - name: Ensure Commet repository ownership is correct on self-build
  39. ansible.builtin.file:
  40. path: "{{ matrix_client_commet_container_src_path }}"
  41. state: directory
  42. owner: "{{ matrix_user_name }}"
  43. group: "{{ matrix_group_name }}"
  44. recurse: true
  45. - name: Ensure Commet repository is present on self-build
  46. ansible.builtin.git:
  47. repo: "{{ matrix_client_commet_container_image_self_build_repo }}"
  48. dest: "{{ matrix_client_commet_container_src_path }}"
  49. version: "{{ matrix_client_commet_version }}"
  50. force: "yes"
  51. become: true
  52. become_user: "{{ matrix_user_name }}"
  53. register: matrix_client_commet_git_pull_results
  54. - name: Set git hash fact
  55. ansible.builtin.set_fact:
  56. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_pull_results.after }}"
  57. - name: Ensure Commet container image is built
  58. ansible.builtin.command:
  59. cmd: |-
  60. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  61. --tag={{ matrix_client_commet_container_image }}
  62. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  63. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  64. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  65. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  66. {{ matrix_client_commet_container_src_path }}
  67. changed_when: true
  68. register: matrix_client_commet_image_build_result
  69. - name: Ensure Commet global_config.json is installed
  70. ansible.builtin.template:
  71. src: "{{ role_path }}/templates/global_config.json.j2"
  72. dest: "{{ matrix_client_commet_config_path }}/global_config.json"
  73. mode: "0644"
  74. owner: "{{ matrix_user_name }}"
  75. group: "{{ matrix_group_name }}"
  76. register: matrix_client_commet_config_result
  77. - name: Ensure Commet support files are installed
  78. ansible.builtin.template:
  79. src: "{{ item.src }}"
  80. dest: "{{ matrix_client_commet_base_path }}/{{ item.name }}"
  81. mode: "0644"
  82. owner: "{{ matrix_user_name }}"
  83. group: "{{ matrix_group_name }}"
  84. with_items:
  85. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  86. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  87. register: matrix_client_commet_support_files_result
  88. - name: Ensure Commet container network is created
  89. when: matrix_client_commet_container_network != 'host'
  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. }}