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

113 строки
4.8 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: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096"
  54. become: true
  55. become_user: "{{ matrix_user_username }}"
  56. when: "not hookshot_passkey_file.stat.exists"
  57. - name: Ensure hookshot config.yml installed if provided
  58. ansible.builtin.copy:
  59. content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  60. dest: "{{ matrix_hookshot_base_path }}/config.yml"
  61. mode: 0644
  62. owner: "{{ matrix_user_username }}"
  63. group: "{{ matrix_user_groupname }}"
  64. - name: Validate hookshot config.yml
  65. ansible.builtin.command:
  66. cmd: |
  67. {{ devture_systemd_docker_base_host_command_docker }} run
  68. --rm
  69. --name={{ matrix_hookshot_container_url }}-validate
  70. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  71. --cap-drop=ALL
  72. -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml
  73. {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml
  74. register: hookshot_config_validation_result
  75. changed_when: false
  76. - name: Fail if hookshot config.yml invalid
  77. ansible.builtin.fail:
  78. msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}"
  79. when: "hookshot_config_validation_result.rc > 0"
  80. - name: Ensure hookshot registration.yml installed if provided
  81. ansible.builtin.copy:
  82. content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}"
  83. dest: "{{ matrix_hookshot_base_path }}/registration.yml"
  84. mode: 0644
  85. owner: "{{ matrix_user_username }}"
  86. group: "{{ matrix_user_groupname }}"
  87. - name: Ensure hookshot github private key file installed if github is enabled
  88. ansible.builtin.copy:
  89. content: "{{ matrix_hookshot_github_private_key }}"
  90. dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}"
  91. mode: 0400
  92. owner: "{{ matrix_user_username }}"
  93. group: "{{ matrix_user_groupname }}"
  94. when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0
  95. - name: Ensure matrix-hookshot.service installed
  96. ansible.builtin.template:
  97. src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2"
  98. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-hookshot.service"
  99. mode: 0644