Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

144 satır
6.0 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Arthur Brugière
  3. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  4. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  5. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  6. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  7. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  8. # SPDX-FileCopyrightText: 2023 Luke Moch
  9. # SPDX-FileCopyrightText: 2024 David Mehren
  10. #
  11. # SPDX-License-Identifier: AGPL-3.0-or-later
  12. ---
  13. - ansible.builtin.include_role:
  14. name: custom/matrix-base
  15. tasks_from: ensure_openssl_installed
  16. - name: Ensure hookshot paths exist
  17. ansible.builtin.file:
  18. path: "{{ item.path }}"
  19. state: directory
  20. mode: 0750
  21. owner: "{{ matrix_user_username }}"
  22. group: "{{ matrix_user_groupname }}"
  23. with_items:
  24. - {path: "{{ matrix_hookshot_base_path }}", when: true}
  25. - {path: "{{ matrix_hookshot_docker_src_files_path }}", when: "{{ matrix_hookshot_container_image_self_build }}"}
  26. when: item.when | bool
  27. - name: Ensure hookshot image is pulled
  28. community.docker.docker_image:
  29. name: "{{ matrix_hookshot_docker_image }}"
  30. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  31. force_source: "{{ matrix_hookshot_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  32. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_hookshot_docker_image_force_pull }}"
  33. when: not matrix_hookshot_container_image_self_build
  34. register: result
  35. retries: "{{ devture_playbook_help_container_retries_count }}"
  36. delay: "{{ devture_playbook_help_container_retries_delay }}"
  37. until: result is not failed
  38. - name: Ensure hookshot repository is present on self-build
  39. ansible.builtin.git:
  40. repo: "{{ matrix_hookshot_container_image_self_build_repo }}"
  41. dest: "{{ matrix_hookshot_docker_src_files_path }}"
  42. version: "{{ matrix_hookshot_container_image_self_build_branch }}"
  43. force: "yes"
  44. become: true
  45. become_user: "{{ matrix_user_username }}"
  46. register: matrix_hookshot_git_pull_results
  47. when: "matrix_hookshot_container_image_self_build | bool"
  48. - name: Ensure hookshot Docker image is built
  49. community.docker.docker_image:
  50. name: "{{ matrix_hookshot_docker_image }}"
  51. source: build
  52. force_source: "{{ matrix_hookshot_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  53. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_hookshot_git_pull_results.changed }}"
  54. build:
  55. dockerfile: Dockerfile
  56. path: "{{ matrix_hookshot_docker_src_files_path }}"
  57. pull: true
  58. when: "matrix_hookshot_container_image_self_build | bool"
  59. - name: Check if hookshot passkey exists
  60. ansible.builtin.stat:
  61. path: "{{ matrix_hookshot_base_path }}/passkey.pem"
  62. register: hookshot_passkey_file
  63. - name: Generate hookshot passkey if it doesn't exist
  64. ansible.builtin.shell:
  65. cmd: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  66. creates: "{{ matrix_hookshot_base_path }}/passkey.pem"
  67. become: true
  68. become_user: "{{ matrix_user_username }}"
  69. when: "not hookshot_passkey_file.stat.exists"
  70. - name: Ensure hookshot config.yml installed if provided
  71. ansible.builtin.copy:
  72. content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  73. dest: "{{ matrix_hookshot_base_path }}/config.yml"
  74. mode: 0644
  75. owner: "{{ matrix_user_username }}"
  76. group: "{{ matrix_user_groupname }}"
  77. - name: Validate hookshot config.yml
  78. ansible.builtin.command:
  79. cmd: |
  80. {{ devture_systemd_docker_base_host_command_docker }} run
  81. --rm
  82. --name={{ matrix_hookshot_container_url }}-validate
  83. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  84. --cap-drop=ALL
  85. --mount type=bind,src={{ matrix_hookshot_base_path }}/config.yml,dst=/config.yml,ro
  86. {{ matrix_hookshot_docker_image }} node config/Config.js /config.yml
  87. register: hookshot_config_validation_result
  88. changed_when: false
  89. - name: Fail if hookshot config.yml invalid
  90. ansible.builtin.fail:
  91. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  92. when: "hookshot_config_validation_result.rc > 0"
  93. - name: Ensure hookshot registration.yml installed if provided
  94. ansible.builtin.copy:
  95. content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  96. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  97. mode: 0644
  98. owner: "{{ matrix_user_username }}"
  99. group: "{{ matrix_user_groupname }}"
  100. - name: Ensure hookshot github private key file installed if github is enabled
  101. ansible.builtin.copy:
  102. content: "{{ matrix_hookshot_github_private_key }}"
  103. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  104. mode: 0400
  105. owner: "{{ matrix_user_username }}"
  106. group: "{{ matrix_user_groupname }}"
  107. when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0
  108. - name: Ensure matrix-hookshot container network is created
  109. community.general.docker_network:
  110. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  111. name: "{{ matrix_hookshot_container_network }}"
  112. driver: bridge
  113. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  114. - name: Ensure mautrix-hookshot support files installed
  115. ansible.builtin.template:
  116. src: "{{ role_path }}/templates/{{ item }}.j2"
  117. dest: "{{ matrix_hookshot_base_path }}/{{ item }}"
  118. mode: 0640
  119. owner: "{{ matrix_user_username }}"
  120. group: "{{ matrix_user_groupname }}"
  121. with_items:
  122. - labels
  123. - name: Ensure matrix-hookshot.service installed
  124. ansible.builtin.template:
  125. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  126. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  127. mode: 0644