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

120 строки
4.9 KiB

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