Matrix Docker Ansible eploy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

145 linhas
6.5 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_docker_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_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_requires_restart: true
  65. - name: Ensure MX Puppet Groupme image is pulled
  66. community.docker.docker_image:
  67. name: "{{ matrix_mx_puppet_groupme_docker_image }}"
  68. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  69. force_source: "{{ matrix_mx_puppet_groupme_docker_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_docker_image_force_pull }}"
  71. when: matrix_mx_puppet_groupme_enabled | bool and not matrix_mx_puppet_groupme_container_image_self_build
  72. register: result
  73. retries: "{{ devture_playbook_help_container_retries_count }}"
  74. delay: "{{ devture_playbook_help_container_retries_delay }}"
  75. until: 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_docker_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_docker_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_docker_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. - name: Ensure mx-puppet-groupme groupme-registration.yaml installed
  105. ansible.builtin.copy:
  106. content: "{{ matrix_mx_puppet_groupme_registration | to_nice_yaml(indent=2, width=999999) }}"
  107. dest: "{{ matrix_mx_puppet_groupme_config_path }}/registration.yaml"
  108. mode: 0644
  109. owner: "{{ matrix_user_name }}"
  110. group: "{{ matrix_group_name }}"
  111. - name: Ensure mx-puppet-groupme container network is created
  112. community.general.docker_network:
  113. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  114. name: "{{ matrix_mx_puppet_groupme_container_network }}"
  115. driver: bridge
  116. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  117. - name: Ensure matrix-mx-puppet-groupme.service installed
  118. ansible.builtin.template:
  119. src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-groupme.service.j2"
  120. dest: "/etc/systemd/system/matrix-mx-puppet-groupme.service"
  121. mode: 0644
  122. - name: Ensure matrix-mx-puppet-groupme.service restarted, if necessary
  123. ansible.builtin.service:
  124. name: "matrix-mx-puppet-groupme.service"
  125. state: restarted
  126. daemon_reload: true
  127. when: "matrix_mx_puppet_groupme_requires_restart | bool"