Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

136 regels
5.6 KiB

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