Matrix Docker Ansible eploy
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

103 lines
4.3 KiB

  1. # SPDX-FileCopyrightText: 2021 Aaron Raimist
  2. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  3. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  6. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  7. # SPDX-FileCopyrightText: 2024 David Mehren
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - ansible.builtin.set_fact:
  12. matrix_bot_mjolnir_migration_requires_restart: false
  13. - name: Ensure matrix-bot-mjolnir paths exist
  14. ansible.builtin.file:
  15. path: "{{ item.path }}"
  16. state: directory
  17. mode: '0750'
  18. owner: "{{ matrix_user_name }}"
  19. group: "{{ matrix_group_name }}"
  20. with_items:
  21. - {path: "{{ matrix_bot_mjolnir_base_path }}", when: true}
  22. - {path: "{{ matrix_bot_mjolnir_config_path }}", when: true}
  23. - {path: "{{ matrix_bot_mjolnir_data_path }}", when: true}
  24. - {path: "{{ matrix_bot_mjolnir_docker_src_files_path }}", when: "{{ matrix_bot_mjolnir_container_image_self_build }}"}
  25. when: "item.when | bool"
  26. - name: Ensure mjolnir Docker image is pulled
  27. community.docker.docker_image:
  28. name: "{{ matrix_bot_mjolnir_docker_image }}"
  29. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  30. force_source: "{{ matrix_bot_mjolnir_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  31. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_mjolnir_docker_image_force_pull }}"
  32. when: "not matrix_bot_mjolnir_container_image_self_build | bool"
  33. register: matrix_bot_mjolnir_container_image_pull_result
  34. retries: "{{ devture_playbook_help_container_retries_count }}"
  35. delay: "{{ devture_playbook_help_container_retries_delay }}"
  36. until: matrix_bot_mjolnir_container_image_pull_result is not failed
  37. - name: Ensure mjolnir repository is present on self-build
  38. ansible.builtin.git:
  39. repo: "{{ matrix_bot_mjolnir_container_image_self_build_repo }}"
  40. dest: "{{ matrix_bot_mjolnir_docker_src_files_path }}"
  41. version: "{{ matrix_bot_mjolnir_docker_image.split(':')[1] }}"
  42. force: "yes"
  43. become: true
  44. become_user: "{{ matrix_user_name }}"
  45. register: matrix_bot_mjolnir_git_pull_results
  46. when: "matrix_bot_mjolnir_container_image_self_build | bool"
  47. - name: Ensure mjolnir Docker image is built
  48. community.docker.docker_image:
  49. name: "{{ matrix_bot_mjolnir_docker_image }}"
  50. source: build
  51. force_source: "{{ matrix_bot_mjolnir_git_pull_results.changed }}"
  52. build:
  53. dockerfile: Dockerfile
  54. path: "{{ matrix_bot_mjolnir_docker_src_files_path }}"
  55. pull: true
  56. when: "matrix_bot_mjolnir_container_image_self_build | bool"
  57. - name: Ensure matrix-bot-mjolnir config installed
  58. ansible.builtin.copy:
  59. content: "{{ matrix_bot_mjolnir_configuration | to_nice_yaml(indent=2, width=999999) }}"
  60. dest: "{{ matrix_bot_mjolnir_config_path }}/production.yaml"
  61. mode: '0644'
  62. owner: "{{ matrix_user_name }}"
  63. group: "{{ matrix_group_name }}"
  64. register: matrix_bot_mjolnir_config_result
  65. - name: Ensure matrix-bot-mjolnir container network is created
  66. community.general.docker_network:
  67. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  68. name: "{{ matrix_bot_mjolnir_container_network }}"
  69. driver: bridge
  70. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  71. - name: Ensure matrix-bot-mjolnir.service installed
  72. ansible.builtin.template:
  73. src: "{{ role_path }}/templates/systemd/matrix-bot-mjolnir.service.j2"
  74. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-mjolnir.service"
  75. mode: '0644'
  76. register: matrix_bot_mjolnir_systemd_service_result
  77. - name: Determine whether Mjolnir needs a restart
  78. ansible.builtin.set_fact:
  79. matrix_bot_mjolnir_restart_necessary: >-
  80. {{
  81. matrix_bot_mjolnir_migration_requires_restart | default(false)
  82. or matrix_bot_mjolnir_config_result.changed | default(false)
  83. or matrix_bot_mjolnir_systemd_service_result.changed | default(false)
  84. or matrix_bot_mjolnir_container_image_pull_result.changed | default(false)
  85. }}
  86. - name: Ensure matrix-bot-mjolnir.service restarted, if necessary
  87. ansible.builtin.service:
  88. name: "matrix-bot-mjolnir.service"
  89. state: restarted
  90. daemon_reload: true
  91. when: "matrix_bot_mjolnir_migration_requires_restart | bool"