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.
 
 

85 lines
3.4 KiB

  1. # SPDX-FileCopyrightText: 2023 - 2025 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2025 Suguru Hirahara
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - name: Ensure Matrix.to path exists
  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_matrixto_base_path }}"
  15. - name: Ensure Matrix.to support files installed
  16. ansible.builtin.template:
  17. src: "{{ role_path }}/templates/{{ item }}.j2"
  18. dest: "{{ matrix_matrixto_base_path }}/{{ item }}"
  19. mode: "0640"
  20. owner: "{{ matrix_user_name }}"
  21. group: "{{ matrix_group_name }}"
  22. with_items:
  23. - env
  24. - labels
  25. register: matrix_matrixto_support_files_result
  26. - name: Ensure Matrix.to repository is present on self-build
  27. ansible.builtin.git:
  28. repo: "{{ matrix_matrixto_container_image_self_build_repo }}"
  29. version: "{{ matrix_matrixto_container_image_self_build_repo_version }}"
  30. dest: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
  31. force: "yes"
  32. register: matrix_matrixto_git_pull_results
  33. - name: Ensure Matrix.to container image is built
  34. community.docker.docker_image_build:
  35. name: "{{ matrix_matrixto_container_image_self_build_name }}"
  36. dockerfile: Dockerfile
  37. path: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
  38. pull: true
  39. rebuild: "{{ 'always' if matrix_matrixto_git_pull_results.changed | bool else 'never' }}"
  40. register: matrix_matrixto_container_image_build_result
  41. - name: Ensure Matrix.to container network is created via community.docker.docker_network
  42. when:
  43. - devture_systemd_docker_base_container_network_creation_method == 'ansible-module'
  44. - matrix_matrixto_container_network != 'host'
  45. community.docker.docker_network:
  46. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  47. name: "{{ matrix_matrixto_container_network }}"
  48. driver: bridge
  49. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  50. - name: Ensure Matrix.to container network is created via ansible.builtin.command
  51. when:
  52. - devture_systemd_docker_base_container_network_creation_method == 'command'
  53. - matrix_matrixto_container_network != 'host'
  54. ansible.builtin.command:
  55. cmd: >-
  56. {{ devture_systemd_docker_base_host_command_docker }} network create
  57. {% if devture_systemd_docker_base_ipv6_enabled %}--ipv6{% endif %}
  58. {{ devture_systemd_docker_base_container_networks_driver_options_string }}
  59. {{ matrix_matrixto_container_network }}
  60. register: network_creation_result
  61. changed_when: network_creation_result.rc == 0
  62. failed_when: network_creation_result.rc != 0 and 'already exists' not in network_creation_result.stderr
  63. - name: Ensure Matrix.to systemd service is present
  64. ansible.builtin.template:
  65. src: "{{ role_path }}/templates/systemd/matrix-matrixto.service.j2"
  66. dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_matrixto_identifier }}.service"
  67. mode: "0644"
  68. register: matrix_matrixto_systemd_service_result
  69. - name: Determine whether Matrix.to needs a restart
  70. ansible.builtin.set_fact:
  71. matrix_matrixto_restart_necessary: >-
  72. {{
  73. matrix_matrixto_support_files_result.changed | default(false)
  74. or matrix_matrixto_systemd_service_result.changed | default(false)
  75. or matrix_matrixto_container_image_build_result.changed | default(false)
  76. }}