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

114 строки
4.6 KiB

  1. ---
  2. - name: Ensure maubot paths exist
  3. file:
  4. path: "{{ item.path }}"
  5. state: directory
  6. mode: 0755
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - {path: "{{ matrix_bot_maubot_base_path }}", when: true}
  11. - {path: "{{ matrix_bot_maubot_data_path }}", when: true}
  12. - {path: "{{ matrix_bot_maubot_docker_src_files_path }}", when: "{{ matrix_bot_maubot_container_image_self_build }}"}
  13. when: "item.when|bool"
  14. - name: Ensure maubot configuration file created
  15. template:
  16. src: "{{ role_path }}/templates/config/config.yaml.j2"
  17. dest: "{{ matrix_bot_maubot_data_path }}/config.yaml"
  18. owner: "{{ matrix_user_username }}"
  19. group: "{{ matrix_user_groupname }}"
  20. mode: "u=rwx"
  21. - name: Generate Maubot proxying configuration for matrix-nginx-proxy
  22. set_fact:
  23. matrix_bot_maubot_matrix_nginx_proxy_configuration: |
  24. location ~ ^/(_matrix/maubot/.*) {
  25. {% if matrix_nginx_proxy_enabled|default(False) %}
  26. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  27. resolver 127.0.0.11 valid=5s;
  28. set $backend "matrix-maubot:{{ matrix_bot_maubot_port }}/$1";
  29. proxy_pass http://$backend;
  30. proxy_set_header Upgrade $http_upgrade;
  31. proxy_set_header Connection "upgrade";
  32. {% else %}
  33. {# Generic configuration for use outside of our container setup #}
  34. proxy_pass http://127.0.0.1:{{ matrix_bot_maubot_port }}/$1;
  35. proxy_set_header Upgrade $http_upgrade;
  36. proxy_set_header Connection "upgrade";
  37. {% endif %}
  38. }
  39. when: matrix_bot_maubot_proxy_management_interface|bool
  40. - name: Register Maubot's proxying configuration with matrix-nginx-proxy
  41. set_fact:
  42. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  43. {{
  44. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([])
  45. +
  46. [matrix_bot_maubot_matrix_nginx_proxy_configuration]
  47. }}
  48. when: matrix_bot_maubot_proxy_management_interface|bool
  49. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  50. debug:
  51. msg: >-
  52. NOTE: You've enabled Maubot but are not using the matrix-nginx-proxy
  53. reverse proxy.
  54. Please make sure that you're proxying the `/_matrix/maubot`
  55. URL endpoint to the matrix-maubot container.
  56. when: "matrix_bot_maubot_enabled|bool and matrix_bot_maubot_proxy_management_interface|bool and matrix_nginx_proxy_enabled is not defined"
  57. - name: Ensure maubot image is pulled
  58. docker_image:
  59. name: "{{ matrix_bot_maubot_docker_image }}"
  60. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  61. force_source: "{{ matrix_bot_maubot_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  62. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_maubot_docker_image_force_pull }}"
  63. when: "not matrix_bot_maubot_container_image_self_build|bool"
  64. register: result
  65. retries: "{{ matrix_container_retries_count }}"
  66. delay: "{{ matrix_container_retries_delay }}"
  67. until: result is not failed
  68. - name: Ensure maubot repository is present on self-build
  69. git:
  70. repo: "{{ matrix_bot_maubot_docker_repo }}"
  71. dest: "{{ matrix_bot_maubot_docker_src_files_path }}"
  72. force: "yes"
  73. become: true
  74. become_user: "{{ matrix_user_username }}"
  75. register: matrix_bot_maubot_git_pull_results
  76. when: "matrix_bot_maubot_container_image_self_build|bool"
  77. - name: Ensure maubot image is built
  78. docker_image:
  79. name: "{{ matrix_bot_maubot_docker_image }}"
  80. source: build
  81. force_source: "{{ matrix_bot_maubot_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  82. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  83. build:
  84. dockerfile: Dockerfile
  85. path: "{{ matrix_bot_maubot_docker_src_files_path }}"
  86. pull: true
  87. when: "matrix_bot_maubot_container_image_self_build|bool"
  88. - name: Ensure matrix-bot-maubot.service installed
  89. template:
  90. src: "{{ role_path }}/templates/systemd/matrix-bot-maubot.service.j2"
  91. dest: "{{ matrix_systemd_path }}/matrix-bot-maubot.service"
  92. mode: 0644
  93. register: matrix_bot_maubot_systemd_service_result
  94. - name: Ensure systemd reloaded after matrix-bot-maubot.service installation
  95. service:
  96. daemon_reload: true
  97. when: "matrix_bot_maubot_systemd_service_result.changed|bool"
  98. - name: Ensure matrix-bot-maubot.service restarted, if necessary
  99. service:
  100. name: "matrix-bot-maubot.service"
  101. state: restarted