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

166 строки
7.7 KiB

  1. # SPDX-FileCopyrightText: 2024 - 2025 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - name: Ensure WeChat Bridge paths exists
  7. ansible.builtin.file:
  8. path: "{{ item.path }}"
  9. state: directory
  10. mode: '0750'
  11. owner: "{{ matrix_user_name }}"
  12. group: "{{ matrix_group_name }}"
  13. with_items:
  14. - {path: "{{ matrix_bridge_wechat_base_path }}", when: true}
  15. - {path: "{{ matrix_bridge_wechat_config_path }}", when: true}
  16. - {path: "{{ matrix_bridge_wechat_data_path }}", when: true}
  17. - {path: "{{ matrix_bridge_wechat_container_src_files_path }}", when: "{{ matrix_bridge_wechat_container_image_self_build }}"}
  18. - {path: "{{ matrix_bridge_wechat_agent_container_src_files_path }}", when: "{{ matrix_bridge_wechat_agent_container_image_self_build }}"}
  19. when: item.when | bool
  20. - name: Ensure WeChat Bridge image is pulled
  21. community.docker.docker_image_pull:
  22. name: "{{ matrix_bridge_wechat_container_image }}"
  23. pull: always
  24. when: not matrix_bridge_wechat_container_image_self_build
  25. register: matrix_bridge_wechat_container_image_pull_result
  26. retries: "{{ devture_playbook_help_container_retries_count }}"
  27. delay: "{{ devture_playbook_help_container_retries_delay }}"
  28. until: matrix_bridge_wechat_container_image_pull_result is not failed
  29. - when: matrix_bridge_wechat_container_image_self_build | bool
  30. block:
  31. # 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.
  32. - name: Ensure WeChat Bridge repository ownership is correct on self-build
  33. ansible.builtin.file:
  34. path: "{{ matrix_bridge_wechat_container_src_files_path }}"
  35. state: directory
  36. owner: "{{ matrix_user_name }}"
  37. group: "{{ matrix_group_name }}"
  38. recurse: true
  39. - name: Ensure WeChat Bridge repository is present on self-build
  40. ansible.builtin.git:
  41. repo: "{{ matrix_bridge_wechat_container_image_self_build_repo }}"
  42. dest: "{{ matrix_bridge_wechat_container_src_files_path }}"
  43. version: "{{ matrix_bridge_wechat_container_image_self_build_branch }}"
  44. force: "yes"
  45. become: true
  46. become_user: "{{ matrix_user_name }}"
  47. register: matrix_bridge_wechat_git_pull_results
  48. - name: Ensure WeChat Bridge container image is built
  49. community.docker.docker_image_build:
  50. name: "{{ matrix_bridge_wechat_container_image }}"
  51. dockerfile: Dockerfile
  52. path: "{{ matrix_bridge_wechat_container_src_files_path }}"
  53. pull: true
  54. rebuild: "{{ 'always' if matrix_bridge_wechat_git_pull_results.changed | bool else 'never' }}"
  55. register: matrix_bridge_wechat_container_image_build_result
  56. - name: Ensure WeChat Agent image is pulled
  57. community.docker.docker_image_pull:
  58. name: "{{ matrix_bridge_wechat_agent_container_image }}"
  59. pull: always
  60. when: not matrix_bridge_wechat_agent_container_image_self_build
  61. register: matrix_bridge_wechat_agent_container_image_pull_result
  62. retries: "{{ devture_playbook_help_container_retries_count }}"
  63. delay: "{{ devture_playbook_help_container_retries_delay }}"
  64. until: matrix_bridge_wechat_agent_container_image_pull_result is not failed
  65. - when: matrix_bridge_wechat_agent_container_image_self_build | bool
  66. block:
  67. # 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.
  68. - name: Ensure WeChat Agent repository ownership is correct on self-build
  69. ansible.builtin.file:
  70. path: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  71. state: directory
  72. owner: "{{ matrix_user_name }}"
  73. group: "{{ matrix_group_name }}"
  74. recurse: true
  75. - name: Ensure WeChat Agent repository is present on self-build
  76. ansible.builtin.git:
  77. repo: "{{ matrix_bridge_wechat_agent_container_image_self_build_repo }}"
  78. dest: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  79. version: "{{ matrix_bridge_wechat_agent_container_image_self_build_branch }}"
  80. force: "yes"
  81. become: true
  82. become_user: "{{ matrix_user_name }}"
  83. register: matrix_bridge_wechat_agent_git_pull_results
  84. - name: Ensure WeChat Agent container image is built
  85. community.docker.docker_image_build:
  86. name: "{{ matrix_bridge_wechat_agent_container_image }}"
  87. dockerfile: Dockerfile
  88. path: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  89. pull: true
  90. rebuild: "{{ 'always' if matrix_bridge_wechat_agent_git_pull_results.changed | bool else 'never' }}"
  91. register: matrix_bridge_wechat_agent_container_image_build_result
  92. - name: Ensure WeChat configuration installed
  93. ansible.builtin.copy:
  94. content: "{{ matrix_bridge_wechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  95. dest: "{{ matrix_bridge_wechat_config_path }}/config.yaml"
  96. mode: '0644'
  97. owner: "{{ matrix_user_name }}"
  98. group: "{{ matrix_group_name }}"
  99. register: matrix_bridge_wechat_config_result
  100. - name: Ensure WeChat registration.yaml installed
  101. ansible.builtin.copy:
  102. content: "{{ matrix_bridge_wechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  103. dest: "{{ matrix_bridge_wechat_config_path }}/registration.yaml"
  104. mode: '0644'
  105. owner: "{{ matrix_user_name }}"
  106. group: "{{ matrix_group_name }}"
  107. register: matrix_bridge_wechat_registration_result
  108. - name: Ensure Wechat Agent configuration installed
  109. ansible.builtin.copy:
  110. content: "{{ matrix_bridge_wechat_agent_configuration | to_nice_yaml(indent=2, width=999999) }}"
  111. dest: "{{ matrix_bridge_wechat_config_path }}/agent-config.yaml"
  112. mode: '0644'
  113. owner: "{{ matrix_user_name }}"
  114. group: "{{ matrix_group_name }}"
  115. register: matrix_bridge_wechat_agent_config_result
  116. - name: Ensure matrix-wechat container network is created
  117. when: matrix_bridge_wechat_container_network != 'host'
  118. community.general.docker_network:
  119. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  120. name: "{{ matrix_bridge_wechat_container_network }}"
  121. driver: bridge
  122. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  123. - name: Ensure matrix-wechat.service installed
  124. ansible.builtin.template:
  125. src: "{{ role_path }}/templates/systemd/matrix-wechat.service.j2"
  126. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat.service"
  127. mode: '0644'
  128. register: matrix_bridge_wechat_systemd_service_result
  129. - name: Ensure matrix-wechat-agent.service installed
  130. ansible.builtin.template:
  131. src: "{{ role_path }}/templates/systemd/matrix-wechat-agent.service.j2"
  132. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat-agent.service"
  133. mode: '0644'
  134. register: matrix_bridge_wechat_agent_systemd_service_result
  135. - name: Determine whether WeChat Bridge needs a restart
  136. ansible.builtin.set_fact:
  137. matrix_bridge_wechat_restart_necessary: >-
  138. {{
  139. matrix_bridge_wechat_config_result.changed | default(false)
  140. or matrix_bridge_wechat_registration_result.changed | default(false)
  141. or matrix_bridge_wechat_agent_config_result.changed | default(false)
  142. or matrix_bridge_wechat_systemd_service_result.changed | default(false)
  143. or matrix_bridge_wechat_agent_systemd_service_result.changed | default(false)
  144. or matrix_bridge_wechat_container_image_pull_result.changed | default(false)
  145. or matrix_bridge_wechat_agent_container_image_pull_result.changed | default(false)
  146. or matrix_bridge_wechat_container_image_build_result.changed | default(false)
  147. or matrix_bridge_wechat_agent_container_image_build_result.changed | default(false)
  148. }}