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

115 строки
4.7 KiB

  1. ---
  2. - import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml"
  3. - name: Ensure hookshot paths exist
  4. 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. 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. 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. 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. 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. command: |
  64. {{ matrix_host_command_docker }} run
  65. --rm
  66. --name={{ matrix_hookshot_container_url }}-validate
  67. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  68. --cap-drop=ALL
  69. -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml
  70. {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml
  71. register: hookshot_config_validation_result
  72. - name: Fail if hookshot config.yml invalid
  73. fail:
  74. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  75. when: "hookshot_config_validation_result.rc > 0"
  76. - name: Ensure hookshot registration.yml installed if provided
  77. copy:
  78. content: "{{ matrix_hookshot_registration|to_nice_yaml(indent=2, width=999999) }}"
  79. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  80. mode: 0644
  81. owner: "{{ matrix_user_username }}"
  82. group: "{{ matrix_user_groupname }}"
  83. - name: Ensure hookshot github private key file installed if github is enabled
  84. copy:
  85. content: "{{ matrix_hookshot_github_private_key }}"
  86. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  87. mode: 0400
  88. owner: "{{ matrix_user_username }}"
  89. group: "{{ matrix_user_groupname }}"
  90. when: matrix_hookshot_github_enabled|bool and matrix_hookshot_github_private_key|length > 0
  91. - name: Ensure matrix-hookshot.service installed
  92. template:
  93. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  94. dest: "{{ matrix_systemd_path }}/matrix-hookshot.service"
  95. mode: 0644
  96. register: matrix_hookshot_systemd_service_result
  97. - name: Ensure systemd reloaded after matrix-hookshot.service installation
  98. service:
  99. daemon_reload: true
  100. when: matrix_hookshot_systemd_service_result.changed