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.
 
 
 

159 lines
7.0 KiB

  1. # SPDX-FileCopyrightText: 2026 MDAD project contributors
  2. # SPDX-FileCopyrightText: 2026 Nikita Chernyi
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - ansible.builtin.set_fact:
  7. matrix_bridge_beeper_line_migration_requires_restart: false
  8. - when: "matrix_bridge_beeper_line_database_engine == 'postgres'"
  9. block:
  10. - name: Check if an SQLite database already exists
  11. ansible.builtin.stat:
  12. path: "{{ matrix_bridge_beeper_line_sqlite_database_path_local }}"
  13. register: matrix_bridge_beeper_line_sqlite_database_path_local_stat_result
  14. - when: "matrix_bridge_beeper_line_sqlite_database_path_local_stat_result.stat.exists | bool"
  15. block:
  16. - ansible.builtin.include_role:
  17. name: galaxy/postgres
  18. tasks_from: migrate_db_to_postgres
  19. vars:
  20. postgres_db_migration_request:
  21. src: "{{ matrix_bridge_beeper_line_sqlite_database_path_local }}"
  22. dst: "{{ matrix_bridge_beeper_line_database_connection_string }}"
  23. caller: "{{ role_path | basename }}"
  24. engine_variable_name: 'matrix_bridge_beeper_line_database_engine'
  25. engine_old: 'sqlite'
  26. systemd_services_to_stop: ['matrix-beeper-line.service']
  27. pgloader_options: ['--with "quote identifiers"']
  28. - ansible.builtin.set_fact:
  29. matrix_bridge_beeper_line_migration_requires_restart: true
  30. - name: Ensure Beeper LINE paths exist
  31. ansible.builtin.file:
  32. path: "{{ item.path }}"
  33. state: directory
  34. mode: '0750'
  35. owner: "{{ matrix_user_name }}"
  36. group: "{{ matrix_group_name }}"
  37. with_items:
  38. - {path: "{{ matrix_bridge_beeper_line_base_path }}", when: true}
  39. - {path: "{{ matrix_bridge_beeper_line_config_path }}", when: true}
  40. - {path: "{{ matrix_bridge_beeper_line_data_path }}", when: true}
  41. - {path: "{{ matrix_bridge_beeper_line_container_src_files_path }}", when: "{{ matrix_bridge_beeper_line_container_image_self_build }}"}
  42. when: item.when | bool
  43. - name: Ensure Beeper LINE image is pulled
  44. community.docker.docker_image_pull:
  45. name: "{{ matrix_bridge_beeper_line_container_image }}"
  46. pull: always
  47. when: not matrix_bridge_beeper_line_container_image_self_build
  48. register: matrix_bridge_beeper_line_container_image_pull_result
  49. retries: "{{ devture_playbook_help_container_retries_count }}"
  50. delay: "{{ devture_playbook_help_container_retries_delay }}"
  51. until: matrix_bridge_beeper_line_container_image_pull_result is not failed
  52. # 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.
  53. - name: Ensure Beeper LINE repository ownership is correct on self-build
  54. ansible.builtin.file:
  55. path: "{{ matrix_bridge_beeper_line_container_src_files_path }}"
  56. state: directory
  57. owner: "{{ matrix_user_name }}"
  58. group: "{{ matrix_group_name }}"
  59. recurse: true
  60. when: "matrix_bridge_beeper_line_container_image_self_build | bool"
  61. - name: Ensure Beeper LINE repository is present on self-build
  62. ansible.builtin.git:
  63. repo: "{{ matrix_bridge_beeper_line_container_image_self_build_repo }}"
  64. dest: "{{ matrix_bridge_beeper_line_container_src_files_path }}"
  65. version: "{{ matrix_bridge_beeper_line_container_image_self_build_branch }}"
  66. force: "yes"
  67. become: true
  68. become_user: "{{ matrix_user_name }}"
  69. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  70. environment:
  71. GIT_CONFIG_COUNT: "1"
  72. GIT_CONFIG_KEY_0: safe.directory
  73. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_beeper_line_container_src_files_path }}"
  74. register: matrix_bridge_beeper_line_git_pull_results
  75. when: "matrix_bridge_beeper_line_container_image_self_build | bool"
  76. - name: Ensure Beeper LINE Docker image is built
  77. community.docker.docker_image_build:
  78. name: "{{ matrix_bridge_beeper_line_container_image }}"
  79. dockerfile: Dockerfile
  80. path: "{{ matrix_bridge_beeper_line_container_src_files_path }}"
  81. pull: true
  82. rebuild: "{{ 'always' if matrix_bridge_beeper_line_git_pull_results.changed | bool else 'never' }}"
  83. when: "matrix_bridge_beeper_line_container_image_self_build | bool"
  84. register: matrix_bridge_beeper_line_container_image_build_result
  85. - name: Ensure beeper-line config.yaml installed
  86. ansible.builtin.copy:
  87. content: "{{ matrix_bridge_beeper_line_configuration | to_nice_yaml(indent=2, width=999999) }}"
  88. dest: "{{ matrix_bridge_beeper_line_config_path }}/config.yaml"
  89. mode: '0644'
  90. owner: "{{ matrix_user_name }}"
  91. group: "{{ matrix_group_name }}"
  92. register: matrix_bridge_beeper_line_config_result
  93. - name: Ensure beeper-line registration.yaml installed
  94. ansible.builtin.copy:
  95. content: "{{ matrix_bridge_beeper_line_registration | to_nice_yaml(indent=2, width=999999) }}"
  96. dest: "{{ matrix_bridge_beeper_line_config_path }}/registration.yaml"
  97. mode: '0644'
  98. owner: "{{ matrix_user_name }}"
  99. group: "{{ matrix_group_name }}"
  100. register: matrix_bridge_beeper_line_registration_result
  101. - name: Ensure matrix-beeper-line.service installed
  102. ansible.builtin.template:
  103. src: "{{ role_path }}/templates/systemd/matrix-beeper-line.service.j2"
  104. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-beeper-line.service"
  105. mode: '0644'
  106. register: matrix_bridge_beeper_line_systemd_service_result
  107. - name: Ensure beeper-line support files installed
  108. ansible.builtin.template:
  109. src: "{{ role_path }}/templates/{{ item }}.j2"
  110. dest: "{{ matrix_bridge_beeper_line_base_path }}/{{ item }}"
  111. mode: '0640'
  112. owner: "{{ matrix_user_name }}"
  113. group: "{{ matrix_group_name }}"
  114. with_items:
  115. - labels
  116. register: matrix_bridge_beeper_line_support_files_result
  117. - name: Ensure matrix-beeper-line container network is created
  118. when: matrix_bridge_beeper_line_container_network != 'host'
  119. community.general.docker_network:
  120. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  121. name: "{{ matrix_bridge_beeper_line_container_network }}"
  122. driver: bridge
  123. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  124. - name: Determine whether matrix-beeper-line needs a restart
  125. ansible.builtin.set_fact:
  126. matrix_bridge_beeper_line_restart_necessary: >-
  127. {{
  128. matrix_bridge_beeper_line_migration_requires_restart | default(false)
  129. or matrix_bridge_beeper_line_config_result.changed | default(false)
  130. or matrix_bridge_beeper_line_registration_result.changed | default(false)
  131. or matrix_bridge_beeper_line_support_files_result.changed | default(false)
  132. or matrix_bridge_beeper_line_systemd_service_result.changed | default(false)
  133. or matrix_bridge_beeper_line_container_image_pull_result.changed | default(false)
  134. or matrix_bridge_beeper_line_container_image_build_result.changed | default(false)
  135. }}
  136. - name: Ensure matrix-beeper-line.service restarted, if necessary
  137. ansible.builtin.service:
  138. name: "matrix-beeper-line.service"
  139. state: restarted
  140. daemon_reload: true
  141. when: "matrix_bridge_beeper_line_migration_requires_restart | bool"