Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

98 righe
4.2 KiB

  1. # SPDX-FileCopyrightText: 2024 - 2025 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - name: Ensure baibot paths exist
  7. ansible.builtin.file:
  8. path: "{{ item.path }}"
  9. state: directory
  10. mode: '0750'
  11. owner: "{{ matrix_user_name }}"
  12. group: "{{ matrix_group_name }}"
  13. with_items:
  14. - {path: "{{ matrix_bot_baibot_base_path }}", when: true}
  15. - {path: "{{ matrix_bot_baibot_config_path }}", when: true}
  16. - {path: "{{ matrix_bot_baibot_data_path }}", when: true}
  17. - {path: "{{ matrix_bot_baibot_container_src_files_path }}", when: "{{ matrix_bot_baibot_container_image_self_build }}"}
  18. when: "item.when | bool"
  19. - name: Ensure baibot configuration installed
  20. ansible.builtin.copy:
  21. content: "{{ matrix_bot_baibot_configuration | to_nice_yaml(indent=2, width=999999) }}"
  22. dest: "{{ matrix_bot_baibot_config_path }}/config.yml"
  23. mode: '0644'
  24. owner: "{{ matrix_user_name }}"
  25. group: "{{ matrix_group_name }}"
  26. register: matrix_bot_baibot_config_result
  27. - name: Ensure baibot environment variables file created
  28. ansible.builtin.template:
  29. src: "{{ role_path }}/templates/env.j2"
  30. dest: "{{ matrix_bot_baibot_config_path }}/env"
  31. owner: "{{ matrix_user_name }}"
  32. group: "{{ matrix_group_name }}"
  33. mode: '0640'
  34. register: matrix_bot_baibot_env_result
  35. - name: Ensure baibot container image is pulled
  36. community.docker.docker_image:
  37. name: "{{ matrix_bot_baibot_container_image }}"
  38. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  39. force_source: "{{ matrix_bot_baibot_container_image_force_pull 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_bot_baibot_container_image_force_pull }}"
  41. when: "not matrix_bot_baibot_container_image_self_build | bool"
  42. register: matrix_bot_baibot_container_image_pull_result
  43. retries: "{{ devture_playbook_help_container_retries_count }}"
  44. delay: "{{ devture_playbook_help_container_retries_delay }}"
  45. until: matrix_bot_baibot_container_image_pull_result is not failed
  46. - when: "matrix_bot_baibot_container_image_self_build | bool"
  47. block:
  48. - name: Ensure baibot repository is present on self-build
  49. ansible.builtin.git:
  50. repo: "{{ matrix_bot_baibot_container_repo }}"
  51. version: "{{ matrix_bot_baibot_container_repo_version }}"
  52. dest: "{{ matrix_bot_baibot_container_src_files_path }}"
  53. force: "yes"
  54. become: true
  55. become_user: "{{ matrix_user_name }}"
  56. register: matrix_bot_baibot_git_pull_results
  57. - name: Ensure baibot container image is built
  58. community.docker.docker_image:
  59. name: "{{ matrix_bot_baibot_container_image }}"
  60. source: build
  61. force_source: "{{ matrix_bot_baibot_git_pull_results.changed 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_baibot_git_pull_results.changed }}"
  63. build:
  64. dockerfile: Dockerfile
  65. path: "{{ matrix_bot_baibot_container_src_files_path }}"
  66. pull: true
  67. - name: Ensure baibot container network is created
  68. community.general.docker_network:
  69. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  70. name: "{{ matrix_bot_baibot_container_network }}"
  71. driver: bridge
  72. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  73. - name: Ensure matrix-bot-baibot.service installed
  74. ansible.builtin.template:
  75. src: "{{ role_path }}/templates/systemd/matrix-bot-baibot.service.j2"
  76. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-baibot.service"
  77. mode: '0644'
  78. register: matrix_bot_baibot_systemd_service_result
  79. - name: Determine whether baibot needs a restart
  80. ansible.builtin.set_fact:
  81. matrix_bot_baibot_restart_necessary: >-
  82. {{
  83. matrix_bot_baibot_config_result.changed | default(false)
  84. or matrix_bot_baibot_env_result.changed | default(false)
  85. or matrix_bot_baibot_systemd_service_result.changed | default(false)
  86. or matrix_bot_baibot_container_image_pull_result.changed | default(false)
  87. }}