Matrix Docker Ansible eploy
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 

159 рядки
7.4 KiB

  1. # SPDX-FileCopyrightText: 2021 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2021 Cody Neiman
  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. - name: Ensure MX Puppet Groupme paths exist
  12. ansible.builtin.file:
  13. path: "{{ item.path }}"
  14. state: directory
  15. mode: '0750'
  16. owner: "{{ matrix_user_name }}"
  17. group: "{{ matrix_group_name }}"
  18. with_items:
  19. - {path: "{{ matrix_mx_puppet_groupme_base_path }}", when: true}
  20. - {path: "{{ matrix_mx_puppet_groupme_config_path }}", when: true}
  21. - {path: "{{ matrix_mx_puppet_groupme_data_path }}", when: true}
  22. - {path: "{{ matrix_mx_puppet_groupme_container_src_files_path }}", when: "{{ matrix_mx_puppet_groupme_container_image_self_build }}"}
  23. when: matrix_mx_puppet_groupme_enabled | bool and item.when | bool
  24. - name: Check if an old database file already exists
  25. ansible.builtin.stat:
  26. path: "{{ matrix_mx_puppet_groupme_base_path }}/database.db"
  27. register: matrix_mx_puppet_groupme_stat_database
  28. - name: (Data relocation) Ensure matrix-mx-puppet-groupme.service is stopped
  29. ansible.builtin.service:
  30. name: matrix-mx-puppet-groupme
  31. state: stopped
  32. enabled: false
  33. daemon_reload: true
  34. failed_when: false
  35. when: "matrix_mx_puppet_groupme_stat_database.stat.exists"
  36. - name: (Data relocation) Move mx-puppet-groupme database file to ./data directory
  37. ansible.builtin.command:
  38. cmd: "mv {{ matrix_mx_puppet_groupme_base_path }}/database.db {{ matrix_mx_puppet_groupme_data_path }}/database.db"
  39. creates: "{{ matrix_mx_puppet_groupme_data_path }}/database.db"
  40. removes: "{{ matrix_mx_puppet_groupme_base_path }}/database.db"
  41. when: "matrix_mx_puppet_groupme_stat_database.stat.exists"
  42. - ansible.builtin.set_fact:
  43. matrix_mx_puppet_groupme_migration_requires_restart: false
  44. - when: "matrix_mx_puppet_groupme_database_engine == 'postgres'"
  45. block:
  46. - name: Check if an SQLite database already exists
  47. ansible.builtin.stat:
  48. path: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}"
  49. register: matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result
  50. - when: "matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result.stat.exists | bool"
  51. block:
  52. - ansible.builtin.include_role:
  53. name: galaxy/postgres
  54. tasks_from: migrate_db_to_postgres
  55. vars:
  56. postgres_db_migration_request:
  57. src: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}"
  58. dst: "{{ matrix_mx_puppet_groupme_database_connection_string }}"
  59. caller: "{{ role_path | basename }}"
  60. engine_variable_name: 'matrix_mx_puppet_groupme_database_engine'
  61. engine_old: 'sqlite'
  62. systemd_services_to_stop: ['matrix-mx-puppet-groupme.service']
  63. - ansible.builtin.set_fact:
  64. matrix_mx_puppet_groupme_migration_requires_restart: true
  65. - name: Ensure MX Puppet Groupme image is pulled
  66. community.docker.docker_image:
  67. name: "{{ matrix_mx_puppet_groupme_container_image }}"
  68. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  69. force_source: "{{ matrix_mx_puppet_groupme_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  70. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mx_puppet_groupme_container_image_force_pull }}"
  71. when: matrix_mx_puppet_groupme_enabled | bool and not matrix_mx_puppet_groupme_container_image_self_build
  72. register: matrix_mx_puppet_groupme_container_image_pull_result
  73. retries: "{{ devture_playbook_help_container_retries_count }}"
  74. delay: "{{ devture_playbook_help_container_retries_delay }}"
  75. until: matrix_mx_puppet_groupme_container_image_pull_result is not failed
  76. - name: Ensure MX Puppet Groupme repository is present on self build
  77. ansible.builtin.git:
  78. repo: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo }}"
  79. version: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo_version }}"
  80. dest: "{{ matrix_mx_puppet_groupme_container_src_files_path }}"
  81. force: "yes"
  82. become: true
  83. become_user: "{{ matrix_user_name }}"
  84. register: matrix_mx_puppet_groupme_git_pull_results
  85. when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build"
  86. - name: Ensure MX Puppet Groupme Docker image is built
  87. community.docker.docker_image:
  88. name: "{{ matrix_mx_puppet_groupme_container_image }}"
  89. source: build
  90. force_source: "{{ matrix_mx_puppet_groupme_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  91. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mx_puppet_groupme_git_pull_results.changed }}"
  92. build:
  93. dockerfile: Dockerfile
  94. path: "{{ matrix_mx_puppet_groupme_container_src_files_path }}"
  95. pull: true
  96. when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build"
  97. - name: Ensure mx-puppet-groupme config.yaml installed
  98. ansible.builtin.copy:
  99. content: "{{ matrix_mx_puppet_groupme_configuration | to_nice_yaml(indent=2, width=999999) }}"
  100. dest: "{{ matrix_mx_puppet_groupme_config_path }}/config.yaml"
  101. mode: '0644'
  102. owner: "{{ matrix_user_name }}"
  103. group: "{{ matrix_group_name }}"
  104. register: matrix_mx_puppet_groupme_config_result
  105. - name: Ensure mx-puppet-groupme groupme-registration.yaml installed
  106. ansible.builtin.copy:
  107. content: "{{ matrix_mx_puppet_groupme_registration | to_nice_yaml(indent=2, width=999999) }}"
  108. dest: "{{ matrix_mx_puppet_groupme_config_path }}/registration.yaml"
  109. mode: '0644'
  110. owner: "{{ matrix_user_name }}"
  111. group: "{{ matrix_group_name }}"
  112. register: matrix_mx_puppet_groupme_registration_result
  113. - name: Ensure mx-puppet-groupme container network is created
  114. community.general.docker_network:
  115. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  116. name: "{{ matrix_mx_puppet_groupme_container_network }}"
  117. driver: bridge
  118. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  119. - name: Ensure matrix-mx-puppet-groupme.service installed
  120. ansible.builtin.template:
  121. src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-groupme.service.j2"
  122. dest: "/etc/systemd/system/matrix-mx-puppet-groupme.service"
  123. mode: '0644'
  124. register: matrix_mx_puppet_groupme_systemd_service_result
  125. - name: Determine whether matrix-mx-puppet-groupme needs a restart
  126. ansible.builtin.set_fact:
  127. matrix_mx_puppet_groupme_restart_necessary: >-
  128. {{
  129. matrix_mx_puppet_groupme_migration_requires_restart | default(false)
  130. or matrix_mx_puppet_groupme_config_result.changed | default(false)
  131. or matrix_mx_puppet_groupme_registration_result.changed | default(false)
  132. or matrix_mx_puppet_groupme_systemd_service_result.changed | default(false)
  133. or matrix_mx_puppet_groupme_container_image_pull_result.changed | default(false)
  134. }}
  135. - name: Ensure matrix-mx-puppet-groupme.service restarted, if necessary
  136. ansible.builtin.service:
  137. name: "matrix-mx-puppet-groupme.service"
  138. state: restarted
  139. daemon_reload: true
  140. when: "matrix_mx_puppet_groupme_migration_requires_restart | bool"