Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

139 lines
6.2 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Julian-Samuel Gebühr
  3. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  4. # SPDX-FileCopyrightText: 2022 Stuart Mumford
  5. # SPDX-FileCopyrightText: 2024 David Mehren
  6. # SPDX-FileCopyrightText: 2025 Suguru Hirahara
  7. #
  8. # SPDX-License-Identifier: AGPL-3.0-or-later
  9. ---
  10. - name: Ensure maubot paths exist
  11. ansible.builtin.file:
  12. path: "{{ item.path }}"
  13. state: directory
  14. mode: '0755'
  15. owner: "{{ matrix_user_name }}"
  16. group: "{{ matrix_group_name }}"
  17. with_items:
  18. - {path: "{{ matrix_bot_maubot_base_path }}", when: true}
  19. - {path: "{{ matrix_bot_maubot_config_path }}", when: true}
  20. - {path: "{{ matrix_bot_maubot_data_path }}", when: true}
  21. - {path: "{{ matrix_bot_maubot_data_path }}/plugins", when: true}
  22. - {path: "{{ matrix_bot_maubot_data_path }}/dbs", when: true}
  23. - {path: "{{ matrix_bot_maubot_data_path }}/trash", when: true}
  24. - {path: "{{ matrix_bot_maubot_container_src_files_path }}", when: "{{ matrix_bot_maubot_container_image_self_build }}"}
  25. - {path: "{{ matrix_bot_maubot_customized_container_src_files_path }}", when: "{{ matrix_bot_maubot_container_image_customizations_enabled }}"}
  26. when: "item.when|bool"
  27. - name: Ensure maubot configuration file created
  28. ansible.builtin.template:
  29. src: "{{ role_path }}/templates/config.yaml.j2"
  30. dest: "{{ matrix_bot_maubot_config_path }}/config.yaml"
  31. owner: "{{ matrix_user_name }}"
  32. group: "{{ matrix_group_name }}"
  33. mode: "u=rwx"
  34. register: matrix_bot_maubot_config_result
  35. - name: Ensure maubot image is pulled
  36. community.docker.docker_image_pull:
  37. name: "{{ matrix_bot_maubot_container_image }}"
  38. pull: always
  39. when: "not matrix_bot_maubot_container_image_self_build|bool"
  40. register: matrix_bot_maubot_container_image_pull_result
  41. retries: "{{ devture_playbook_help_container_retries_count }}"
  42. delay: "{{ devture_playbook_help_container_retries_delay }}"
  43. until: matrix_bot_maubot_container_image_pull_result is not failed
  44. - when: matrix_bot_maubot_container_image_self_build | bool
  45. block:
  46. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  47. - name: Ensure maubot repository ownership is correct on self-build
  48. ansible.builtin.file:
  49. path: "{{ matrix_bot_maubot_container_src_files_path }}"
  50. state: directory
  51. owner: "{{ matrix_user_name }}"
  52. group: "{{ matrix_group_name }}"
  53. recurse: true
  54. - name: Ensure maubot repository is present on self-build
  55. ansible.builtin.git:
  56. repo: "{{ matrix_bot_maubot_container_repo }}"
  57. version: "{{ matrix_bot_maubot_container_repo_version }}"
  58. dest: "{{ matrix_bot_maubot_container_src_files_path }}"
  59. force: "yes"
  60. become: true
  61. become_user: "{{ matrix_user_name }}"
  62. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  63. environment:
  64. GIT_CONFIG_COUNT: "1"
  65. GIT_CONFIG_KEY_0: safe.directory
  66. GIT_CONFIG_VALUE_0: "{{ matrix_bot_maubot_container_src_files_path }}"
  67. register: matrix_bot_maubot_git_pull_results
  68. - name: Ensure maubot image is built
  69. community.docker.docker_image_build:
  70. name: "{{ matrix_bot_maubot_container_image }}"
  71. dockerfile: Dockerfile
  72. path: "{{ matrix_bot_maubot_container_src_files_path }}"
  73. pull: true
  74. rebuild: "{{ 'always' if matrix_bot_maubot_git_pull_results.changed | bool else 'never' }}"
  75. register: matrix_bot_maubot_container_image_build_result
  76. - when: "matrix_bot_maubot_container_image_customizations_enabled | bool"
  77. block:
  78. - name: Ensure customizations Dockerfile is created
  79. ansible.builtin.template:
  80. src: "{{ role_path }}/templates/customizations/Dockerfile.j2"
  81. dest: "{{ matrix_bot_maubot_customized_container_src_files_path }}/Dockerfile"
  82. owner: "{{ matrix_user_name }}"
  83. group: "{{ matrix_group_name }}"
  84. mode: '0640'
  85. register: matrix_bot_maubot_container_image_customizations_dockerfile_result
  86. - name: Ensure customized Docker image for maubot is built
  87. community.docker.docker_image_build:
  88. name: "{{ matrix_bot_maubot_container_image_customized }}"
  89. dockerfile: Dockerfile
  90. path: "{{ matrix_bot_maubot_customized_container_src_files_path }}"
  91. nocache: "{{ matrix_bot_maubot_container_image_customized_build_nocache }}"
  92. rebuild: "{{ 'always' if (matrix_bot_maubot_container_image_customizations_dockerfile_result.changed or matrix_bot_maubot_container_image_customized_force_source) | bool else 'never' }}"
  93. - name: Ensure maubot support files installed
  94. ansible.builtin.template:
  95. src: "{{ role_path }}/templates/{{ item }}.j2"
  96. dest: "{{ matrix_bot_maubot_base_path }}/{{ item }}"
  97. mode: '0640'
  98. owner: "{{ matrix_user_name }}"
  99. group: "{{ matrix_group_name }}"
  100. with_items:
  101. - labels
  102. register: matrix_bot_maubot_support_files_result
  103. - name: Ensure maubot container network is created
  104. when: matrix_bot_maubot_container_network != 'host'
  105. community.general.docker_network:
  106. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  107. name: "{{ matrix_bot_maubot_container_network }}"
  108. driver: bridge
  109. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  110. - name: Ensure matrix-bot-maubot.service installed
  111. ansible.builtin.template:
  112. src: "{{ role_path }}/templates/systemd/matrix-bot-maubot.service.j2"
  113. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-maubot.service"
  114. mode: '0644'
  115. register: matrix_bot_maubot_systemd_service_result
  116. - name: Determine whether maubot needs a restart
  117. ansible.builtin.set_fact:
  118. matrix_bot_maubot_restart_necessary: >-
  119. {{
  120. matrix_bot_maubot_config_result.changed | default(false)
  121. or matrix_bot_maubot_support_files_result.changed | default(false)
  122. or matrix_bot_maubot_systemd_service_result.changed | default(false)
  123. or matrix_bot_maubot_container_image_pull_result.changed | default(false)
  124. or matrix_bot_maubot_container_image_build_result.changed | default(false)
  125. }}