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

176 строки
8.3 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. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  48. environment:
  49. GIT_CONFIG_COUNT: "1"
  50. GIT_CONFIG_KEY_0: safe.directory
  51. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_wechat_container_src_files_path }}"
  52. register: matrix_bridge_wechat_git_pull_results
  53. - name: Ensure WeChat Bridge container image is built
  54. community.docker.docker_image_build:
  55. name: "{{ matrix_bridge_wechat_container_image }}"
  56. dockerfile: Dockerfile
  57. path: "{{ matrix_bridge_wechat_container_src_files_path }}"
  58. pull: true
  59. rebuild: "{{ 'always' if matrix_bridge_wechat_git_pull_results.changed | bool else 'never' }}"
  60. register: matrix_bridge_wechat_container_image_build_result
  61. - name: Ensure WeChat Agent image is pulled
  62. community.docker.docker_image_pull:
  63. name: "{{ matrix_bridge_wechat_agent_container_image }}"
  64. pull: always
  65. when: not matrix_bridge_wechat_agent_container_image_self_build
  66. register: matrix_bridge_wechat_agent_container_image_pull_result
  67. retries: "{{ devture_playbook_help_container_retries_count }}"
  68. delay: "{{ devture_playbook_help_container_retries_delay }}"
  69. until: matrix_bridge_wechat_agent_container_image_pull_result is not failed
  70. - when: matrix_bridge_wechat_agent_container_image_self_build | bool
  71. block:
  72. # 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.
  73. - name: Ensure WeChat Agent repository ownership is correct on self-build
  74. ansible.builtin.file:
  75. path: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  76. state: directory
  77. owner: "{{ matrix_user_name }}"
  78. group: "{{ matrix_group_name }}"
  79. recurse: true
  80. - name: Ensure WeChat Agent repository is present on self-build
  81. ansible.builtin.git:
  82. repo: "{{ matrix_bridge_wechat_agent_container_image_self_build_repo }}"
  83. dest: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  84. version: "{{ matrix_bridge_wechat_agent_container_image_self_build_branch }}"
  85. force: "yes"
  86. become: true
  87. become_user: "{{ matrix_user_name }}"
  88. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  89. environment:
  90. GIT_CONFIG_COUNT: "1"
  91. GIT_CONFIG_KEY_0: safe.directory
  92. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  93. register: matrix_bridge_wechat_agent_git_pull_results
  94. - name: Ensure WeChat Agent container image is built
  95. community.docker.docker_image_build:
  96. name: "{{ matrix_bridge_wechat_agent_container_image }}"
  97. dockerfile: Dockerfile
  98. path: "{{ matrix_bridge_wechat_agent_container_src_files_path }}"
  99. pull: true
  100. rebuild: "{{ 'always' if matrix_bridge_wechat_agent_git_pull_results.changed | bool else 'never' }}"
  101. register: matrix_bridge_wechat_agent_container_image_build_result
  102. - name: Ensure WeChat configuration installed
  103. ansible.builtin.copy:
  104. content: "{{ matrix_bridge_wechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  105. dest: "{{ matrix_bridge_wechat_config_path }}/config.yaml"
  106. mode: '0644'
  107. owner: "{{ matrix_user_name }}"
  108. group: "{{ matrix_group_name }}"
  109. register: matrix_bridge_wechat_config_result
  110. - name: Ensure WeChat registration.yaml installed
  111. ansible.builtin.copy:
  112. content: "{{ matrix_bridge_wechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  113. dest: "{{ matrix_bridge_wechat_config_path }}/registration.yaml"
  114. mode: '0644'
  115. owner: "{{ matrix_user_name }}"
  116. group: "{{ matrix_group_name }}"
  117. register: matrix_bridge_wechat_registration_result
  118. - name: Ensure Wechat Agent configuration installed
  119. ansible.builtin.copy:
  120. content: "{{ matrix_bridge_wechat_agent_configuration | to_nice_yaml(indent=2, width=999999) }}"
  121. dest: "{{ matrix_bridge_wechat_config_path }}/agent-config.yaml"
  122. mode: '0644'
  123. owner: "{{ matrix_user_name }}"
  124. group: "{{ matrix_group_name }}"
  125. register: matrix_bridge_wechat_agent_config_result
  126. - name: Ensure matrix-wechat container network is created
  127. when: matrix_bridge_wechat_container_network != 'host'
  128. community.general.docker_network:
  129. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  130. name: "{{ matrix_bridge_wechat_container_network }}"
  131. driver: bridge
  132. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  133. - name: Ensure matrix-wechat.service installed
  134. ansible.builtin.template:
  135. src: "{{ role_path }}/templates/systemd/matrix-wechat.service.j2"
  136. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat.service"
  137. mode: '0644'
  138. register: matrix_bridge_wechat_systemd_service_result
  139. - name: Ensure matrix-wechat-agent.service installed
  140. ansible.builtin.template:
  141. src: "{{ role_path }}/templates/systemd/matrix-wechat-agent.service.j2"
  142. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat-agent.service"
  143. mode: '0644'
  144. register: matrix_bridge_wechat_agent_systemd_service_result
  145. - name: Determine whether WeChat Bridge needs a restart
  146. ansible.builtin.set_fact:
  147. matrix_bridge_wechat_restart_necessary: >-
  148. {{
  149. matrix_bridge_wechat_config_result.changed | default(false)
  150. or matrix_bridge_wechat_registration_result.changed | default(false)
  151. or matrix_bridge_wechat_agent_config_result.changed | default(false)
  152. or matrix_bridge_wechat_systemd_service_result.changed | default(false)
  153. or matrix_bridge_wechat_agent_systemd_service_result.changed | default(false)
  154. or matrix_bridge_wechat_container_image_pull_result.changed | default(false)
  155. or matrix_bridge_wechat_agent_container_image_pull_result.changed | default(false)
  156. or matrix_bridge_wechat_container_image_build_result.changed | default(false)
  157. or matrix_bridge_wechat_agent_container_image_build_result.changed | default(false)
  158. }}