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.
 
 

97 rivejä
3.9 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_bot_draupnir_requires_restart: false
  7. - name: Ensure matrix-bot-draupnir 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_bot_draupnir_base_path }}", when: true}
  16. - {path: "{{ matrix_bot_draupnir_config_path }}", when: true}
  17. - {path: "{{ matrix_bot_draupnir_data_path }}", when: true}
  18. - {path: "{{ matrix_bot_draupnir_docker_src_files_path }}", when: "{{ matrix_bot_draupnir_container_image_self_build }}"}
  19. when: "item.when | bool"
  20. - name: Ensure matrix-bot-draupnir support files installed
  21. ansible.builtin.template:
  22. src: "{{ item.src }}"
  23. dest: "{{ item.dest }}"
  24. owner: "{{ matrix_user_username }}"
  25. group: "{{ matrix_user_groupname }}"
  26. mode: 0644
  27. with_items:
  28. - src: "{{ role_path }}/templates/labels.j2"
  29. dest: "{{ matrix_bot_draupnir_base_path }}/labels"
  30. - name: Ensure Draupnir Docker image is pulled
  31. community.docker.docker_image:
  32. name: "{{ matrix_bot_draupnir_docker_image }}"
  33. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  34. force_source: "{{ matrix_bot_draupnir_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  35. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_draupnir_docker_image_force_pull }}"
  36. when: "not matrix_bot_draupnir_container_image_self_build | bool"
  37. register: result
  38. retries: "{{ devture_playbook_help_container_retries_count }}"
  39. delay: "{{ devture_playbook_help_container_retries_delay }}"
  40. until: result is not failed
  41. - name: Ensure Draupnir repository is present on self-build
  42. ansible.builtin.git:
  43. repo: "{{ matrix_bot_draupnir_container_image_self_build_repo }}"
  44. dest: "{{ matrix_bot_draupnir_docker_src_files_path }}"
  45. version: "{{ matrix_bot_draupnir_docker_image.split(':')[1] }}"
  46. force: "yes"
  47. become: true
  48. become_user: "{{ matrix_user_username }}"
  49. register: matrix_bot_draupnir_git_pull_results
  50. when: "matrix_bot_draupnir_container_image_self_build | bool"
  51. - name: Ensure Draupnir Docker image is built
  52. community.docker.docker_image:
  53. name: "{{ matrix_bot_draupnir_docker_image }}"
  54. source: build
  55. force_source: "{{ matrix_bot_draupnir_git_pull_results.changed }}"
  56. build:
  57. dockerfile: Dockerfile
  58. path: "{{ matrix_bot_draupnir_docker_src_files_path }}"
  59. pull: true
  60. when: "matrix_bot_draupnir_container_image_self_build | bool"
  61. - name: Ensure matrix-bot-draupnir config installed
  62. ansible.builtin.copy:
  63. content: "{{ matrix_bot_draupnir_configuration | to_nice_yaml(indent=2, width=999999) }}"
  64. dest: "{{ matrix_bot_draupnir_config_path }}/production.yaml"
  65. mode: 0644
  66. owner: "{{ matrix_user_username }}"
  67. group: "{{ matrix_user_groupname }}"
  68. - name: Ensure matrix-bot-draupnir container network is created
  69. community.general.docker_network:
  70. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  71. name: "{{ matrix_bot_draupnir_container_network }}"
  72. driver: bridge
  73. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  74. - name: Ensure matrix-bot-draupnir.service installed
  75. ansible.builtin.template:
  76. src: "{{ role_path }}/templates/systemd/matrix-bot-draupnir.service.j2"
  77. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-draupnir.service"
  78. mode: 0644
  79. register: matrix_bot_draupnir_systemd_service_result
  80. - name: Ensure matrix-bot-draupnir.service restarted, if necessary
  81. ansible.builtin.service:
  82. name: "matrix-bot-draupnir.service"
  83. state: restarted
  84. daemon_reload: true
  85. when: "matrix_bot_draupnir_requires_restart | bool"