Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

77 líneas
2.6 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"
  7. - name: Fail if playbook called incorrectly
  8. fail:
  9. msg: "The `server_path_postgres_dump` variable needs to be provided to this playbook, via --extra-vars"
  10. when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')"
  11. - name: Check if the provided Postgres dump file exists
  12. stat:
  13. path: "{{ server_path_postgres_dump }}"
  14. register: result_server_path_postgres_dump_stat
  15. - name: Fail if provided Postgres dump file doesn't exists
  16. fail:
  17. msg: "File cannot be found on the server at {{ server_path_postgres_dump }}"
  18. when: not result_server_path_postgres_dump_stat.stat.exists
  19. # Defaults
  20. - name: Set postgres_start_wait_time, if not provided
  21. set_fact:
  22. postgres_start_wait_time: 15
  23. when: "postgres_start_wait_time|default('') == ''"
  24. # Actual import work
  25. - name: Ensure matrix-postgres is started
  26. service:
  27. name: matrix-postgres
  28. state: started
  29. daemon_reload: yes
  30. - name: Wait a bit, so that Postgres can start
  31. wait_for:
  32. timeout: "{{ postgres_start_wait_time }}"
  33. delegate_to: 127.0.0.1
  34. become: false
  35. - import_tasks: tasks/util/detect_existing_postgres_version.yml
  36. - name: Abort, if no existing Postgres version detected
  37. fail:
  38. msg: "Could not find existing Postgres installation"
  39. when: "not matrix_postgres_detected_existing"
  40. - name: Generate Postgres database import command
  41. set_fact:
  42. matrix_postgres_import_command: >-
  43. /usr/bin/docker run --rm --name matrix-postgres-import
  44. --network={{ matrix_docker_network }}
  45. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql
  46. -v {{ server_path_postgres_dump }}:{{ server_path_postgres_dump }}:ro
  47. --entrypoint=/bin/sh
  48. {{ matrix_postgres_docker_image_latest }}
  49. -c 'cat {{ server_path_postgres_dump }} |
  50. {{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }}
  51. psql -v ON_ERROR_STOP=1 -h matrix-postgres'
  52. - name: Note about Postgres importing alternative
  53. debug:
  54. msg: >
  55. Importing Postgres database using the following command: `{{ matrix_postgres_import_command }}`.
  56. If this crashes, you can stop Postgres (`systemctl stop matrix-postgres`),
  57. delete its existing data (`rm -rf {{ matrix_postgres_data_path }}/*`), start it again (`systemctl start matrix-postgres`)
  58. and manually run the above import command directly on the server.
  59. - name: Perform Postgres database import
  60. command: "{{ matrix_postgres_import_command }}"