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

117 строки
4.9 KiB

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