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.
 
 

102 lines
4.8 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - ansible.builtin.set_fact:
  6. matrix_appservice_draupnir_for_all_requires_restart: false
  7. - name: Ensure matrix-appservice-draupnir-for-all paths exist
  8. ansible.builtin.file:
  9. path: "{{ item.path }}"
  10. state: directory
  11. mode: 0750
  12. owner: "{{ matrix_user_username }}"
  13. group: "{{ matrix_user_groupname }}"
  14. with_items:
  15. - {path: "{{ matrix_appservice_draupnir_for_all_base_path }}", when: true}
  16. - {path: "{{ matrix_appservice_draupnir_for_all_config_path }}", when: true}
  17. - {path: "{{ matrix_appservice_draupnir_for_all_data_path }}", when: true}
  18. - {path: "{{ matrix_appservice_draupnir_for_all_docker_src_files_path }}", when: "{{ matrix_appservice_draupnir_for_all_container_image_self_build }}"}
  19. when: "item.when | bool"
  20. - name: Ensure Draupnir Docker image is pulled
  21. community.docker.docker_image:
  22. name: "{{ matrix_appservice_draupnir_for_all_docker_image }}"
  23. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  24. force_source: "{{ matrix_appservice_draupnir_for_all_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  25. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_draupnir_for_all_docker_image_force_pull }}"
  26. when: "not matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  27. register: result
  28. retries: "{{ devture_playbook_help_container_retries_count }}"
  29. delay: "{{ devture_playbook_help_container_retries_delay }}"
  30. until: result is not failed
  31. - name: Ensure Draupnir repository is present on self-build
  32. ansible.builtin.git:
  33. repo: "{{ matrix_appservice_draupnir_for_all_container_image_self_build_repo }}"
  34. dest: "{{ matrix_appservice_draupnir_for_all_docker_src_files_path }}"
  35. version: "{{ matrix_appservice_draupnir_for_all_docker_image.split(':')[1] }}"
  36. force: "yes"
  37. become: true
  38. become_user: "{{ matrix_user_username }}"
  39. register: matrix_appservice_draupnir_for_all_git_pull_results
  40. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  41. - name: Ensure Draupnir Docker image is built
  42. community.docker.docker_image:
  43. name: "{{ matrix_appservice_draupnir_for_all_docker_image }}"
  44. source: build
  45. force_source: "{{ matrix_appservice_draupnir_for_all_git_pull_results.changed }}"
  46. build:
  47. dockerfile: Dockerfile
  48. path: "{{ matrix_appservice_draupnir_for_all_docker_src_files_path }}"
  49. pull: true
  50. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  51. - name: Ensure matrix-appservice-draupnir-for-all appservice config installed
  52. ansible.builtin.copy:
  53. content: "{{ matrix_appservice_draupnir_for_all_configuration_appservice | to_nice_yaml(indent=2, width=999999) }}"
  54. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-appservice.yaml"
  55. mode: 0644
  56. owner: "{{ matrix_user_username }}"
  57. group: "{{ matrix_user_groupname }}"
  58. - name: Ensure matrix-appservice-draupnir-for-all bot config installed
  59. ansible.builtin.copy:
  60. content: "{{ matrix_appservice_draupnir_for_all_configuration | to_nice_yaml(indent=2, width=999999) }}"
  61. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-bots.yaml"
  62. mode: 0644
  63. owner: "{{ matrix_user_username }}"
  64. group: "{{ matrix_user_groupname }}"
  65. - name: Ensure matrix-appservice-draupnir-for-all registration.yaml installed
  66. ansible.builtin.copy:
  67. content: "{{ matrix_appservice_draupnir_for_all_registration | to_nice_yaml(indent=2, width=999999) }}"
  68. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/draupnir-for-all-registration.yaml"
  69. mode: 0644
  70. owner: "{{ matrix_user_username }}"
  71. group: "{{ matrix_user_groupname }}"
  72. - name: Ensure matrix-appservice-draupnir-for-all container network is created
  73. community.general.docker_network:
  74. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  75. name: "{{ matrix_appservice_draupnir_for_all_container_network }}"
  76. driver: bridge
  77. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  78. - name: Ensure matrix-appservice-draupnir-for-all.service installed
  79. ansible.builtin.template:
  80. src: "{{ role_path }}/templates/systemd/matrix-appservice-draupnir-for-all.service.j2"
  81. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-draupnir-for-all.service"
  82. mode: 0644
  83. register: matrix_appservice_draupnir_for_all_systemd_service_result
  84. - name: Ensure matrix-appservice-draupnir-for-all.service restarted, if necessary
  85. ansible.builtin.service:
  86. name: "matrix-appservice-draupnir-for-all.service"
  87. state: restarted
  88. daemon_reload: true
  89. when: "matrix_appservice_draupnir_for_all_requires_restart | bool"