Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

130 líneas
5.5 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. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  54. environment:
  55. GIT_CONFIG_COUNT: "1"
  56. GIT_CONFIG_KEY_0: safe.directory
  57. GIT_CONFIG_VALUE_0: "{{ matrix_client_commet_container_src_path }}"
  58. register: matrix_client_commet_git_pull_results
  59. - name: Set git hash fact
  60. ansible.builtin.set_fact:
  61. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_pull_results.after }}"
  62. - name: Ensure Commet container image is built
  63. ansible.builtin.command:
  64. cmd: |-
  65. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  66. --tag={{ matrix_client_commet_container_image }}
  67. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  68. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  69. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  70. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  71. {{ matrix_client_commet_container_src_path }}
  72. changed_when: true
  73. register: matrix_client_commet_image_build_result
  74. - name: Ensure Commet global_config.json is installed
  75. ansible.builtin.template:
  76. src: "{{ role_path }}/templates/global_config.json.j2"
  77. dest: "{{ matrix_client_commet_config_path }}/global_config.json"
  78. mode: "0644"
  79. owner: "{{ matrix_user_name }}"
  80. group: "{{ matrix_group_name }}"
  81. register: matrix_client_commet_config_result
  82. - name: Ensure Commet support files are installed
  83. ansible.builtin.template:
  84. src: "{{ item.src }}"
  85. dest: "{{ matrix_client_commet_base_path }}/{{ item.name }}"
  86. mode: "0644"
  87. owner: "{{ matrix_user_name }}"
  88. group: "{{ matrix_group_name }}"
  89. with_items:
  90. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  91. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  92. register: matrix_client_commet_support_files_result
  93. - name: Ensure Commet container network is created
  94. when: matrix_client_commet_container_network != 'host'
  95. community.general.docker_network:
  96. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  97. name: "{{ matrix_client_commet_container_network }}"
  98. driver: bridge
  99. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  100. - name: Ensure matrix-client-commet.service is installed
  101. ansible.builtin.template:
  102. src: "{{ role_path }}/templates/systemd/matrix-client-commet.service.j2"
  103. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-commet.service"
  104. mode: "0644"
  105. register: matrix_client_commet_systemd_service_result
  106. - name: Determine whether Commet needs a restart
  107. ansible.builtin.set_fact:
  108. matrix_client_commet_restart_necessary: >-
  109. {{
  110. matrix_client_commet_config_result.changed | default(false)
  111. or matrix_client_commet_support_files_result.changed | default(false)
  112. or matrix_client_commet_systemd_service_result.changed | default(false)
  113. or matrix_client_commet_image_build_result.changed | default(false)
  114. or matrix_client_commet_image_pull_result.changed | default(false)
  115. }}