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.

101 lines
4.7 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. - name: Run if self-building of Matrix.to container image is not enabled
  26. when: "not matrix_matrixto_container_image_self_build | bool"
  27. block:
  28. - name: Ensure Matrix.to container image is pulled via community.docker.docker_image
  29. when: devture_systemd_docker_base_container_image_pull_method == 'ansible-module'
  30. community.docker.docker_image:
  31. name: "{{ matrix_matrixto_container_image }}"
  32. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  33. force_source: "{{ matrix_matrixto_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  34. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_matrixto_container_image_force_pull }}"
  35. register: result
  36. retries: "{{ devture_playbook_help_container_retries_count }}"
  37. delay: "{{ devture_playbook_help_container_retries_delay }}"
  38. until: result is not failed
  39. - name: Ensure Matrix.to container image is pulled via ansible.builtin.command
  40. when: devture_systemd_docker_base_container_image_pull_method == 'command'
  41. ansible.builtin.command:
  42. cmd: "{{ devture_systemd_docker_base_host_command_docker }} pull {{ matrix_matrixto_container_image }}"
  43. register: result
  44. retries: "{{ devture_playbook_help_container_retries_count }}"
  45. delay: "{{ devture_playbook_help_container_retries_delay }}"
  46. until: result is not failed
  47. changed_when: "'Downloaded newer image' in result.stdout"
  48. - name: Run if self-building of Matrix.to container image is enabled
  49. when: "matrix_matrixto_container_image_self_build | bool"
  50. block:
  51. - name: Ensure Matrix.to repository is present on self-build
  52. ansible.builtin.git:
  53. repo: "{{ matrix_matrixto_container_image_self_build_repo }}"
  54. version: "{{ matrix_matrixto_container_image_self_build_repo_version }}"
  55. dest: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
  56. force: "yes"
  57. register: matrix_matrixto_git_pull_results
  58. - name: Ensure Matrix.to container image is built
  59. community.docker.docker_image:
  60. name: "{{ matrix_matrixto_container_image_self_build_name }}"
  61. source: build
  62. force_source: "{{ matrix_matrixto_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  63. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_matrixto_git_pull_results.changed }}"
  64. build:
  65. dockerfile: Dockerfile
  66. path: "{{ matrix_matrixto_container_image_self_build_src_files_path }}"
  67. pull: true
  68. args:
  69. - name: Ensure Matrix.to container network is created via community.docker.docker_network
  70. when: devture_systemd_docker_base_container_network_creation_method == 'ansible-module'
  71. community.docker.docker_network:
  72. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  73. name: "{{ matrix_matrixto_container_network }}"
  74. driver: bridge
  75. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  76. - name: Ensure Matrix.to container network is created via ansible.builtin.command
  77. when: devture_systemd_docker_base_container_network_creation_method == 'command'
  78. ansible.builtin.command:
  79. cmd: >-
  80. {{ devture_systemd_docker_base_host_command_docker }} network create
  81. {% if devture_systemd_docker_base_ipv6_enabled %}--ipv6{% endif %}
  82. {{ devture_systemd_docker_base_container_networks_driver_options_string }}
  83. {{ matrix_matrixto_container_network }}
  84. register: network_creation_result
  85. changed_when: network_creation_result.rc == 0
  86. failed_when: network_creation_result.rc != 0 and 'already exists' not in network_creation_result.stderr
  87. - name: Ensure Matrix.to systemd service is present
  88. ansible.builtin.template:
  89. src: "{{ role_path }}/templates/systemd/matrix-matrixto.service.j2"
  90. dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_matrixto_identifier }}.service"
  91. mode: "0644"