Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

147 řádky
6.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_wechat_base_path }}", when: true}
  15. - {path: "{{ matrix_wechat_config_path }}", when: true}
  16. - {path: "{{ matrix_wechat_data_path }}", when: true}
  17. - {path: "{{ matrix_wechat_container_src_files_path }}", when: "{{ matrix_wechat_container_image_self_build }}"}
  18. - {path: "{{ matrix_wechat_agent_container_src_files_path }}", when: "{{ matrix_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_wechat_container_image }}"
  23. pull: always
  24. when: not matrix_wechat_container_image_self_build
  25. register: matrix_wechat_container_image_pull_result
  26. retries: "{{ devture_playbook_help_container_retries_count }}"
  27. delay: "{{ devture_playbook_help_container_retries_delay }}"
  28. until: matrix_wechat_container_image_pull_result is not failed
  29. - when: matrix_wechat_container_image_self_build | bool
  30. block:
  31. - name: Ensure WeChat Bridge repository is present on self-build
  32. ansible.builtin.git:
  33. repo: "{{ matrix_wechat_container_image_self_build_repo }}"
  34. dest: "{{ matrix_wechat_container_src_files_path }}"
  35. version: "{{ matrix_wechat_container_image_self_build_branch }}"
  36. force: "yes"
  37. become: true
  38. become_user: "{{ matrix_user_name }}"
  39. register: matrix_wechat_git_pull_results
  40. - name: Ensure WeChat Bridge container image is built
  41. community.docker.docker_image_build:
  42. name: "{{ matrix_wechat_container_image }}"
  43. dockerfile: Dockerfile
  44. path: "{{ matrix_wechat_container_src_files_path }}"
  45. pull: true
  46. rebuild: "{{ 'always' if matrix_wechat_git_pull_results.changed | bool else 'never' }}"
  47. register: matrix_wechat_container_image_build_result
  48. - name: Ensure WeChat Agent image is pulled
  49. community.docker.docker_image_pull:
  50. name: "{{ matrix_wechat_agent_container_image }}"
  51. pull: always
  52. when: not matrix_wechat_agent_container_image_self_build
  53. register: matrix_wechat_agent_container_image_pull_result
  54. retries: "{{ devture_playbook_help_container_retries_count }}"
  55. delay: "{{ devture_playbook_help_container_retries_delay }}"
  56. until: matrix_wechat_agent_container_image_pull_result is not failed
  57. - when: matrix_wechat_agent_container_image_self_build | bool
  58. block:
  59. - name: Ensure WeChat Agent repository is present on self-build
  60. ansible.builtin.git:
  61. repo: "{{ matrix_wechat_agent_container_image_self_build_repo }}"
  62. dest: "{{ matrix_wechat_agent_container_src_files_path }}"
  63. version: "{{ matrix_wechat_agent_container_image_self_build_branch }}"
  64. force: "yes"
  65. become: true
  66. become_user: "{{ matrix_user_name }}"
  67. register: matrix_wechat_agent_git_pull_results
  68. - name: Ensure WeChat Agent container image is built
  69. community.docker.docker_image_build:
  70. name: "{{ matrix_wechat_agent_container_image }}"
  71. dockerfile: Dockerfile
  72. path: "{{ matrix_wechat_agent_container_src_files_path }}"
  73. pull: true
  74. rebuild: "{{ 'always' if matrix_wechat_agent_git_pull_results.changed | bool else 'never' }}"
  75. register: matrix_wechat_agent_container_image_build_result
  76. - name: Ensure WeChat configuration installed
  77. ansible.builtin.copy:
  78. content: "{{ matrix_wechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  79. dest: "{{ matrix_wechat_config_path }}/config.yaml"
  80. mode: '0644'
  81. owner: "{{ matrix_user_name }}"
  82. group: "{{ matrix_group_name }}"
  83. register: matrix_wechat_config_result
  84. - name: Ensure WeChat registration.yaml installed
  85. ansible.builtin.copy:
  86. content: "{{ matrix_wechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  87. dest: "{{ matrix_wechat_config_path }}/registration.yaml"
  88. mode: '0644'
  89. owner: "{{ matrix_user_name }}"
  90. group: "{{ matrix_group_name }}"
  91. register: matrix_wechat_registration_result
  92. - name: Ensure Wechat Agent configuration installed
  93. ansible.builtin.copy:
  94. content: "{{ matrix_wechat_agent_configuration | to_nice_yaml(indent=2, width=999999) }}"
  95. dest: "{{ matrix_wechat_config_path }}/agent-config.yaml"
  96. mode: '0644'
  97. owner: "{{ matrix_user_name }}"
  98. group: "{{ matrix_group_name }}"
  99. register: matrix_wechat_agent_config_result
  100. - name: Ensure matrix-wechat container network is created
  101. community.general.docker_network:
  102. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  103. name: "{{ matrix_wechat_container_network }}"
  104. driver: bridge
  105. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  106. - name: Ensure matrix-wechat.service installed
  107. ansible.builtin.template:
  108. src: "{{ role_path }}/templates/systemd/matrix-wechat.service.j2"
  109. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat.service"
  110. mode: '0644'
  111. register: matrix_wechat_systemd_service_result
  112. - name: Ensure matrix-wechat-agent.service installed
  113. ansible.builtin.template:
  114. src: "{{ role_path }}/templates/systemd/matrix-wechat-agent.service.j2"
  115. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-wechat-agent.service"
  116. mode: '0644'
  117. register: matrix_wechat_agent_systemd_service_result
  118. - name: Determine whether WeChat Bridge needs a restart
  119. ansible.builtin.set_fact:
  120. matrix_wechat_restart_necessary: >-
  121. {{
  122. matrix_wechat_config_result.changed | default(false)
  123. or matrix_wechat_registration_result.changed | default(false)
  124. or matrix_wechat_agent_config_result.changed | default(false)
  125. or matrix_wechat_systemd_service_result.changed | default(false)
  126. or matrix_wechat_agent_systemd_service_result.changed | default(false)
  127. or matrix_wechat_container_image_pull_result.changed | default(false)
  128. or matrix_wechat_agent_container_image_pull_result.changed | default(false)
  129. or matrix_wechat_container_image_build_result.changed | default(false)
  130. or matrix_wechat_agent_container_image_build_result.changed | default(false)
  131. }}