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.
 
 

124 lines
5.0 KiB

  1. # SPDX-FileCopyrightText: 2026 MDAD project contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Ensure Commet paths exist
  6. ansible.builtin.file:
  7. path: "{{ item }}"
  8. state: directory
  9. mode: "0750"
  10. owner: "{{ matrix_user_name }}"
  11. group: "{{ matrix_group_name }}"
  12. with_items:
  13. - "{{ matrix_client_commet_base_path }}"
  14. - "{{ matrix_client_commet_config_path }}"
  15. # Self-build tasks — skipped when using a pre-built registry image
  16. - name: Check Commet git remote configuration
  17. ansible.builtin.command:
  18. cmd: git -C "{{ matrix_client_commet_container_src_path }}" remote get-url origin
  19. register: matrix_client_commet_git_remote_check
  20. failed_when: false
  21. changed_when: false
  22. when: matrix_client_commet_container_image_self_build | bool
  23. - name: Remove Commet source directory if git remote is misconfigured
  24. ansible.builtin.file:
  25. path: "{{ matrix_client_commet_container_src_path }}"
  26. state: absent
  27. when: matrix_client_commet_container_image_self_build | bool and matrix_client_commet_git_remote_check.rc != 0
  28. become: true
  29. - name: Ensure Commet repository is present
  30. ansible.builtin.git:
  31. repo: "{{ matrix_client_commet_container_image_self_build_repo }}"
  32. dest: "{{ matrix_client_commet_container_src_path }}"
  33. version: "{{ matrix_client_commet_version }}"
  34. depth: 1
  35. force: true
  36. become: true
  37. become_user: "{{ matrix_user_name }}"
  38. register: matrix_client_commet_git_result
  39. when: matrix_client_commet_container_image_self_build | bool
  40. - name: Capture git hash
  41. ansible.builtin.command:
  42. cmd: git -C {{ matrix_client_commet_container_src_path }} rev-parse --short HEAD
  43. register: matrix_client_commet_git_hash_result
  44. changed_when: false
  45. when: matrix_client_commet_container_image_self_build | bool
  46. - name: Set git hash fact
  47. ansible.builtin.set_fact:
  48. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_hash_result.stdout | trim }}"
  49. when: matrix_client_commet_container_image_self_build | bool
  50. - name: Build Commet Docker image
  51. ansible.builtin.command:
  52. cmd: |-
  53. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  54. --tag={{ matrix_client_commet_container_image }}
  55. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  56. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  57. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  58. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  59. {{ matrix_client_commet_container_src_path }}
  60. changed_when: true
  61. register: matrix_client_commet_image_build_result
  62. when: matrix_client_commet_container_image_self_build | bool
  63. - name: Pull Commet Docker image
  64. ansible.builtin.command:
  65. cmd: "{{ devture_systemd_docker_base_host_command_docker }} pull {{ matrix_client_commet_container_image }}"
  66. register: matrix_client_commet_image_pull_result
  67. changed_when: "'Status: Downloaded newer image' in matrix_client_commet_image_pull_result.stdout"
  68. when: not matrix_client_commet_container_image_self_build | bool
  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. community.general.docker_network:
  90. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  91. name: "{{ matrix_client_commet_container_network }}"
  92. driver: bridge
  93. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  94. - name: Ensure matrix-client-commet.service is installed
  95. ansible.builtin.template:
  96. src: "{{ role_path }}/templates/systemd/matrix-client-commet.service.j2"
  97. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-commet.service"
  98. mode: "0644"
  99. register: matrix_client_commet_systemd_service_result
  100. - name: Determine whether Commet needs a restart
  101. ansible.builtin.set_fact:
  102. matrix_client_commet_restart_necessary: >-
  103. {{
  104. matrix_client_commet_config_result.changed | default(false)
  105. or matrix_client_commet_support_files_result.changed | default(false)
  106. or matrix_client_commet_systemd_service_result.changed | default(false)
  107. or matrix_client_commet_git_result.changed | default(false)
  108. or matrix_client_commet_image_pull_result.changed | default(false)
  109. }}