Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

127 satır
4.6 KiB

  1. ---
  2. - name: Set default postgres_dump_dir, if not provided
  3. set_fact:
  4. postgres_dump_dir: "/tmp"
  5. when: "postgres_dump_dir|default('') == ''"
  6. - name: Set postgres_dump_name, if not provided
  7. set_fact:
  8. postgres_dump_name: "matrix-postgres.out"
  9. when: "postgres_dump_name|default('') == ''"
  10. - name: Set postgres_auto_upgrade_backup_data_path, if not provided
  11. set_fact:
  12. postgres_auto_upgrade_backup_data_path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
  13. when: "postgres_auto_upgrade_backup_data_path|default('') == ''"
  14. - name: Set postgres_start_wait_time, if not provided
  15. set_fact:
  16. postgres_start_wait_time: 15
  17. when: "postgres_start_wait_time|default('') == ''"
  18. - name: Fail, if trying to upgrade external Postgres database
  19. fail:
  20. msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade."
  21. when: "not matrix_postgres_enabled"
  22. - name: Check Postgres auto-upgrade backup data directory
  23. stat:
  24. path: "{{ postgres_auto_upgrade_backup_data_path }}"
  25. register: result_auto_upgrade_path
  26. - name: Abort, if existing Postgres auto-upgrade data path detected
  27. fail:
  28. msg: "Detected that a left-over {{ postgres_auto_upgrade_backup_data_path }} exists. You should rename it to {{ matrix_postgres_data_path }} if the previous upgrade went wrong, or delete it if it went well."
  29. when: "result_auto_upgrade_path.stat.exists"
  30. - import_tasks: tasks/util/detect_existing_postgres_version.yml
  31. - name: Abort, if no existing Postgres version detected
  32. fail:
  33. msg: "Could not find existing Postgres installation"
  34. when: "not matrix_postgres_detected_existing"
  35. - name: Abort, if already at latest Postgres version
  36. fail:
  37. msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do"
  38. when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest"
  39. - debug:
  40. msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}"
  41. - name: Ensure matrix-synapse is stopped
  42. service:
  43. name: matrix-synapse
  44. state: stopped
  45. - name: Ensure matrix-postgres is started
  46. service:
  47. name: matrix-postgres
  48. state: started
  49. daemon_reload: yes
  50. - name: Wait a bit, so that Postgres can start
  51. wait_for:
  52. timeout: "{{ postgres_start_wait_time }}"
  53. delegate_to: 127.0.0.1
  54. become: false
  55. - name: Perform Postgres database dump
  56. command: |
  57. /usr/bin/docker run --rm --name matrix-postgres-dump \
  58. --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
  59. --network={{ matrix_docker_network }} \
  60. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql \
  61. -v {{ postgres_dump_dir }}:/out \
  62. {{ matrix_postgres_detected_version_corresponding_docker_image }} pg_dump -h matrix-postgres {{ matrix_postgres_db_name }} -f /out/{{ postgres_dump_name }}
  63. - name: Ensure matrix-postgres is stopped
  64. service:
  65. name: matrix-postgres
  66. state: stopped
  67. - name: Rename existing Postgres data directory
  68. command: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}"
  69. - debug:
  70. msg: "NOTE: Your Postgres data directory has been moved from `{{ matrix_postgres_data_path }}` to `{{ postgres_auto_upgrade_backup_data_path }}`. In the event of failure, you can move it back and run the playbook with --tags=setup-postgres to restore operation."
  71. - import_tasks: tasks/setup_postgres.yml
  72. - name: Ensure matrix-postgres autoruns and is restarted
  73. service:
  74. name: matrix-postgres
  75. enabled: yes
  76. state: restarted
  77. daemon_reload: yes
  78. - name: Wait a bit, so that Postgres can start
  79. wait_for:
  80. timeout: "{{ postgres_start_wait_time }}"
  81. delegate_to: 127.0.0.1
  82. become: false
  83. - name: Perform Postgres database import
  84. command: |
  85. /usr/bin/docker run --rm --name matrix-postgres-import \
  86. --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
  87. --network={{ matrix_docker_network }} \
  88. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql \
  89. -v {{ postgres_dump_dir }}:/in:ro \
  90. {{ matrix_postgres_docker_image_latest }} psql -v ON_ERROR_STOP=1 -h matrix-postgres -f /in/{{ postgres_dump_name }}
  91. - name: Delete Postgres database dump file
  92. file:
  93. path: "{{ postgres_dump_dir }}/{{ postgres_dump_name }}"
  94. state: absent
  95. - name: Ensure matrix-synapse is started
  96. service:
  97. name: matrix-synapse
  98. state: started
  99. daemon_reload: yes
  100. - debug:
  101. msg: "NOTE: Your old Postgres data directory is preserved at `{{ postgres_auto_upgrade_backup_data_path }}`. You might want to get rid of it once you've confirmed that all is well."