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.
 
 
 

172 lines
8.3 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_bridge_mx_puppet_groupme_base_path }}", when: true}
  20. - {path: "{{ matrix_bridge_mx_puppet_groupme_config_path }}", when: true}
  21. - {path: "{{ matrix_bridge_mx_puppet_groupme_data_path }}", when: true}
  22. - {path: "{{ matrix_bridge_mx_puppet_groupme_container_src_files_path }}", when: "{{ matrix_bridge_mx_puppet_groupme_container_image_self_build }}"}
  23. when: matrix_bridge_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_bridge_mx_puppet_groupme_base_path }}/database.db"
  27. register: matrix_bridge_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_bridge_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_bridge_mx_puppet_groupme_base_path }}/database.db {{ matrix_bridge_mx_puppet_groupme_data_path }}/database.db"
  39. creates: "{{ matrix_bridge_mx_puppet_groupme_data_path }}/database.db"
  40. removes: "{{ matrix_bridge_mx_puppet_groupme_base_path }}/database.db"
  41. when: "matrix_bridge_mx_puppet_groupme_stat_database.stat.exists"
  42. - ansible.builtin.set_fact:
  43. matrix_bridge_mx_puppet_groupme_migration_requires_restart: false
  44. - when: "matrix_bridge_mx_puppet_groupme_database_engine == 'postgres'"
  45. block:
  46. - name: Check if an SQLite database already exists
  47. ansible.builtin.stat:
  48. path: "{{ matrix_bridge_mx_puppet_groupme_sqlite_database_path_local }}"
  49. register: matrix_bridge_mx_puppet_groupme_sqlite_database_path_local_stat_result
  50. - when: "matrix_bridge_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_bridge_mx_puppet_groupme_sqlite_database_path_local }}"
  58. dst: "{{ matrix_bridge_mx_puppet_groupme_database_connection_string }}"
  59. caller: "{{ role_path | basename }}"
  60. engine_variable_name: 'matrix_bridge_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_bridge_mx_puppet_groupme_migration_requires_restart: true
  65. - name: Ensure MX Puppet Groupme image is pulled
  66. community.docker.docker_image_pull:
  67. name: "{{ matrix_bridge_mx_puppet_groupme_container_image }}"
  68. pull: always
  69. when: matrix_bridge_mx_puppet_groupme_enabled | bool and not matrix_bridge_mx_puppet_groupme_container_image_self_build
  70. register: matrix_bridge_mx_puppet_groupme_container_image_pull_result
  71. retries: "{{ devture_playbook_help_container_retries_count }}"
  72. delay: "{{ devture_playbook_help_container_retries_delay }}"
  73. until: matrix_bridge_mx_puppet_groupme_container_image_pull_result is not failed
  74. # 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.
  75. - name: Ensure MX Puppet Groupme repository ownership is correct on self build
  76. ansible.builtin.file:
  77. path: "{{ matrix_bridge_mx_puppet_groupme_container_src_files_path }}"
  78. state: directory
  79. owner: "{{ matrix_user_name }}"
  80. group: "{{ matrix_group_name }}"
  81. recurse: true
  82. when: "matrix_bridge_mx_puppet_groupme_enabled | bool and matrix_bridge_mx_puppet_groupme_container_image_self_build"
  83. - name: Ensure MX Puppet Groupme repository is present on self build
  84. ansible.builtin.git:
  85. repo: "{{ matrix_bridge_mx_puppet_groupme_container_image_self_build_repo }}"
  86. version: "{{ matrix_bridge_mx_puppet_groupme_container_image_self_build_repo_version }}"
  87. dest: "{{ matrix_bridge_mx_puppet_groupme_container_src_files_path }}"
  88. force: "yes"
  89. become: true
  90. become_user: "{{ matrix_user_name }}"
  91. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  92. environment:
  93. GIT_CONFIG_COUNT: "1"
  94. GIT_CONFIG_KEY_0: safe.directory
  95. GIT_CONFIG_VALUE_0: "{{ matrix_bridge_mx_puppet_groupme_container_src_files_path }}"
  96. register: matrix_bridge_mx_puppet_groupme_git_pull_results
  97. when: "matrix_bridge_mx_puppet_groupme_enabled | bool and matrix_bridge_mx_puppet_groupme_container_image_self_build"
  98. - name: Ensure MX Puppet Groupme Docker image is built
  99. community.docker.docker_image_build:
  100. name: "{{ matrix_bridge_mx_puppet_groupme_container_image }}"
  101. dockerfile: Dockerfile
  102. path: "{{ matrix_bridge_mx_puppet_groupme_container_src_files_path }}"
  103. pull: true
  104. rebuild: "{{ 'always' if matrix_bridge_mx_puppet_groupme_git_pull_results.changed | bool else 'never' }}"
  105. when: "matrix_bridge_mx_puppet_groupme_enabled | bool and matrix_bridge_mx_puppet_groupme_container_image_self_build"
  106. register: matrix_bridge_mx_puppet_groupme_container_image_build_result
  107. - name: Ensure mx-puppet-groupme config.yaml installed
  108. ansible.builtin.copy:
  109. content: "{{ matrix_bridge_mx_puppet_groupme_configuration | to_nice_yaml(indent=2, width=999999) }}"
  110. dest: "{{ matrix_bridge_mx_puppet_groupme_config_path }}/config.yaml"
  111. mode: '0644'
  112. owner: "{{ matrix_user_name }}"
  113. group: "{{ matrix_group_name }}"
  114. register: matrix_bridge_mx_puppet_groupme_config_result
  115. - name: Ensure mx-puppet-groupme groupme-registration.yaml installed
  116. ansible.builtin.copy:
  117. content: "{{ matrix_bridge_mx_puppet_groupme_registration | to_nice_yaml(indent=2, width=999999) }}"
  118. dest: "{{ matrix_bridge_mx_puppet_groupme_config_path }}/registration.yaml"
  119. mode: '0644'
  120. owner: "{{ matrix_user_name }}"
  121. group: "{{ matrix_group_name }}"
  122. register: matrix_bridge_mx_puppet_groupme_registration_result
  123. - name: Ensure mx-puppet-groupme container network is created
  124. when: matrix_bridge_mx_puppet_groupme_container_network != 'host'
  125. community.general.docker_network:
  126. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  127. name: "{{ matrix_bridge_mx_puppet_groupme_container_network }}"
  128. driver: bridge
  129. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  130. - name: Ensure matrix-mx-puppet-groupme.service installed
  131. ansible.builtin.template:
  132. src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-groupme.service.j2"
  133. dest: "/etc/systemd/system/matrix-mx-puppet-groupme.service"
  134. mode: '0644'
  135. register: matrix_bridge_mx_puppet_groupme_systemd_service_result
  136. - name: Determine whether matrix-mx-puppet-groupme needs a restart
  137. ansible.builtin.set_fact:
  138. matrix_bridge_mx_puppet_groupme_restart_necessary: >-
  139. {{
  140. matrix_bridge_mx_puppet_groupme_migration_requires_restart | default(false)
  141. or matrix_bridge_mx_puppet_groupme_config_result.changed | default(false)
  142. or matrix_bridge_mx_puppet_groupme_registration_result.changed | default(false)
  143. or matrix_bridge_mx_puppet_groupme_systemd_service_result.changed | default(false)
  144. or matrix_bridge_mx_puppet_groupme_container_image_pull_result.changed | default(false)
  145. or matrix_bridge_mx_puppet_groupme_container_image_build_result.changed | default(false)
  146. }}
  147. - name: Ensure matrix-mx-puppet-groupme.service restarted, if necessary
  148. ansible.builtin.service:
  149. name: "matrix-mx-puppet-groupme.service"
  150. state: restarted
  151. daemon_reload: true
  152. when: "matrix_bridge_mx_puppet_groupme_migration_requires_restart | bool"