Matrix Docker Ansible eploy
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

131 linhas
5.4 KiB

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