Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

112 строки
5.2 KiB

  1. ---
  2. - name: Fail if Postgres not enabled
  3. fail:
  4. msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate."
  5. when: "not matrix_postgres_enabled|bool"
  6. - name: Fail if util called incorrectly (missing matrix_postgres_db_migration_request)
  7. fail:
  8. msg: "The `matrix_postgres_db_migration_request` variable needs to be provided to this util."
  9. when: "matrix_postgres_db_migration_request is not defined"
  10. - name: Fail if util called incorrectly (invalid matrix_postgres_db_migration_request)
  11. fail:
  12. msg: "The `matrix_postgres_db_migration_request` variable needs to contain `{{ item }}`."
  13. with_items:
  14. - src
  15. - dst
  16. - caller
  17. - engine_variable_name
  18. - systemd_services_to_stop
  19. when: "item not in matrix_postgres_db_migration_request"
  20. - name: Check if the provided source database file exists
  21. stat:
  22. path: "{{ matrix_postgres_db_migration_request.src }}"
  23. register: matrix_postgres_db_migration_request_src_stat_result
  24. - name: Fail if provided source database file doesn't exist
  25. fail:
  26. msg: "File cannot be found on the server at {{ matrix_postgres_db_migration_request.src }}"
  27. when: "not matrix_postgres_db_migration_request_src_stat_result.stat.exists"
  28. - name: Fail if we cannot migrate on the current architecture ({{ matrix_architecture }})
  29. fail:
  30. msg: >-
  31. {{ matrix_postgres_db_migration_request.engine_variable_name }} (part of {{ matrix_postgres_db_migration_request.caller }}) has been set to `postgres` (which is our new default now).
  32. However, we've discovered an existing file-based database ({{ matrix_postgres_db_migration_request.engine_old }}) in {{ matrix_postgres_db_migration_request.src }}.
  33. It appears that you've been using this bridge with a file-based database engine until now.
  34. To continue using {{ matrix_postgres_db_migration_request.engine_old }}, opt into it explicitly: add `{{ matrix_postgres_db_migration_request.engine_variable_name }}: {{ matrix_postgres_db_migration_request.engine_old }}` to your vars.yml file and re-run this same command.
  35. We'd normally auto-migrate you to Postgres, but we can't do it on the {{ matrix_architecture }} architecture. Our pgloader container image only supports amd64 (for now).
  36. Learn more here: https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/740
  37. when: "matrix_architecture != 'amd64'"
  38. # Defaults
  39. - name: Set postgres_start_wait_time, if not provided
  40. set_fact:
  41. postgres_start_wait_time: 15
  42. when: "postgres_start_wait_time|default('') == ''"
  43. # Actual import work
  44. # matrix-postgres is most likely started already
  45. - name: Ensure matrix-postgres is started
  46. service:
  47. name: matrix-postgres
  48. state: started
  49. daemon_reload: yes
  50. register: matrix_postgres_service_start_result
  51. - name: Wait a bit, so that Postgres can start
  52. wait_for:
  53. timeout: "{{ postgres_start_wait_time }}"
  54. delegate_to: 127.0.0.1
  55. become: false
  56. when: "matrix_postgres_service_start_result.changed|bool"
  57. # We only stop services here, leaving it to the caller to start them later.
  58. #
  59. # We can't start them, because they probably need to be reconfigured too (changing the configuration from using SQLite to Postgres, etc.),
  60. # before starting.
  61. #
  62. # Since the caller will be starting them, it might make sense to leave stopping to it as well.
  63. # However, we don't do it, because it's simpler having it here, and it also gets to happen only if we'll be doing an import.
  64. # If we bailed out (somewhere above), nothing would have gotten stopped. It's nice to leave this running in such cases.
  65. - name: Ensure systemd services blocking the database import are stopped
  66. service:
  67. name: "{{ item }}"
  68. state: stopped
  69. with_items: "{{ matrix_postgres_db_migration_request.systemd_services_to_stop }}"
  70. - name: Import {{ matrix_postgres_db_migration_request.engine_old }} database from {{ matrix_postgres_db_migration_request.src }} into Postgres
  71. command:
  72. cmd: >-
  73. {{ matrix_host_command_docker }} run
  74. --rm
  75. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  76. --cap-drop=ALL
  77. --network={{ matrix_docker_network }}
  78. --mount type=bind,src={{ matrix_postgres_db_migration_request.src }},dst=/in.db,ro
  79. --entrypoint=/bin/sh
  80. {{ matrix_postgres_pgloader_docker_image }}
  81. -c
  82. 'pgloader {{ matrix_postgres_db_migration_request.pgloader_options|default([])|join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}'
  83. - name: Archive {{ matrix_postgres_db_migration_request.engine_old }} database ({{ matrix_postgres_db_migration_request.src }} -> {{ matrix_postgres_db_migration_request.src }}.backup)
  84. command:
  85. cmd: "mv {{ matrix_postgres_db_migration_request.src }} {{ matrix_postgres_db_migration_request.src }}.backup"
  86. - name: Inject result
  87. set_fact:
  88. matrix_playbook_runtime_results: |
  89. {{
  90. matrix_playbook_runtime_results|default([])
  91. +
  92. [
  93. "NOTE: Your {{ matrix_postgres_db_migration_request.engine_old }} database file has been imported into Postgres. The original database file has been moved from `{{ matrix_postgres_db_migration_request.src }}` to `{{ matrix_postgres_db_migration_request.src }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file."
  94. ]
  95. }}