Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

98 righe
3.8 KiB

  1. ---
  2. # Pre-checks
  3. - name: Fail if Postgres not enabled
  4. fail:
  5. msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
  6. when: "not matrix_postgres_enabled|bool"
  7. - name: Fail if playbook called incorrectly
  8. fail:
  9. msg: "The `sqlite_database_path` variable needs to be provided to this playbook, via --extra-vars"
  10. when: "sqlite_database_path is not defined or sqlite_database_path.startswith('<')"
  11. - name: Check if the provided SQLite database file exists
  12. stat:
  13. path: "{{ sqlite_database_path }}"
  14. register: sqlite_database_path_stat_result
  15. - name: Fail if provided SQLite database file doesn't exist
  16. fail:
  17. msg: "File cannot be found on the server at {{ sqlite_database_path }}"
  18. when: "not sqlite_database_path_stat_result.stat.exists"
  19. # We either expect `postgres_db_connection_string` specifying a full Postgres database connection string,
  20. # or `postgres_connection_string_variable_name`, specifying a name of a variable, which contains a valid connection string.
  21. - block:
  22. - name: Fail if postgres_connection_string_variable_name points to an undefined variable
  23. fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`"
  24. when: "postgres_connection_string_variable_name not in vars"
  25. - name: Get Postgres connection string from variable
  26. set_fact:
  27. postgres_db_connection_string: "{{ lookup('vars', postgres_connection_string_variable_name) }}"
  28. when: 'postgres_connection_string_variable_name is defined'
  29. - name: Fail if playbook called incorrectly
  30. fail:
  31. msg: >-
  32. Either a `postgres_db_connection_string` variable or a `postgres_connection_string_variable_name` needs to be provided to this playbook, via `--extra-vars`.
  33. Example: `--extra-vars="postgres_db_connection_string=postgresql://username:password@localhost:<port>/database_name"` or `--extra-vars="postgres_connection_string_variable_name=matrix_appservice_discord_database_connString"`
  34. when: "postgres_db_connection_string is not defined or not postgres_db_connection_string.startswith('postgresql://')"
  35. # Defaults
  36. - name: Set postgres_start_wait_time, if not provided
  37. set_fact:
  38. postgres_start_wait_time: 15
  39. when: "postgres_start_wait_time|default('') == ''"
  40. # Actual import work
  41. - name: Ensure matrix-postgres is started
  42. service:
  43. name: matrix-postgres
  44. state: started
  45. daemon_reload: yes
  46. register: matrix_postgres_service_start_result
  47. - name: Wait a bit, so that Postgres can start
  48. wait_for:
  49. timeout: "{{ postgres_start_wait_time }}"
  50. delegate_to: 127.0.0.1
  51. become: false
  52. when: "matrix_postgres_service_start_result.changed|bool"
  53. - name: Import SQLite database from {{ sqlite_database_path }} into Postgres
  54. command:
  55. cmd: >-
  56. {{ matrix_host_command_docker }} run
  57. --rm
  58. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  59. --cap-drop=ALL
  60. --network={{ matrix_docker_network }}
  61. --mount type=bind,src={{ sqlite_database_path }},dst=/in.db,ro
  62. --entrypoint=/bin/sh
  63. {{ matrix_postgres_pgloader_docker_image }}
  64. -c
  65. 'pgloader /in.db {{ postgres_db_connection_string }}'
  66. - name: Archive SQLite database ({{ sqlite_database_path }} -> {{ sqlite_database_path }}.backup)
  67. command:
  68. cmd: "mv {{ sqlite_database_path }} {{ sqlite_database_path }}.backup"
  69. - name: Inject result
  70. set_fact:
  71. matrix_playbook_runtime_results: |
  72. {{
  73. matrix_playbook_runtime_results|default([])
  74. +
  75. [
  76. "NOTE: Your SQLite database file has been imported into Postgres. The original file has been moved from `{{ sqlite_database_path }}` to `{{ sqlite_database_path }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file."
  77. ]
  78. }}