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.
 
 

79 linhas
3.4 KiB

  1. ---
  2. # We used to store Postgres data directly under `/matrix/postgres` (what is now considered `matrix_postgres_base_path`).
  3. #
  4. # From now on, we expect to store Postgres data one directory below now (`/matrix/postgres/data` - `matrix_postgres_data_path`).
  5. # We wish to use the base directory for other purposes (storing environment variable files, etc.).
  6. # Mixing those with the Postgres data is no good and it leads to Postgres's `initdb` complaining to initialize
  7. # a database in a non-empty directory.
  8. #
  9. # For this reason, we store the Postgres data in `/matrix/postgres/data` and need to relocate any installations
  10. # which still store it in the parent directory (`/matrix/postgres`).
  11. #
  12. # This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible
  13. # to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html
  14. - name: Check if old Postgres data directory is used
  15. ansible.builtin.stat:
  16. path: "{{ matrix_postgres_base_path }}/PG_VERSION"
  17. register: result_pg_old_data_dir_stat
  18. - name: Warn if old Postgres data directory detected
  19. ansible.builtin.debug:
  20. msg: >
  21. Found that you have Postgres data in `{{ matrix_postgres_base_path }}`.
  22. From now on, Postgres data is supposed to be stored in `{{ matrix_postgres_data_path }}` instead.
  23. We'll stop Postgres and relocate the files there for you.
  24. when: "result_pg_old_data_dir_stat.stat.exists"
  25. # We should stop Postgres first, before building a list of files,
  26. # as to ignore any `postmaster.pid` files, etc.
  27. - name: Ensure matrix-postgres is stopped
  28. ansible.builtin.service:
  29. name: matrix-postgres
  30. state: stopped
  31. daemon_reload: true
  32. when: "result_pg_old_data_dir_stat.stat.exists"
  33. - name: Find files and directories in old Postgres data path
  34. ansible.builtin.find:
  35. paths: "{{ matrix_postgres_base_path }}"
  36. file_type: any
  37. excludes: ["data"]
  38. register: "result_pg_old_data_dir_find"
  39. when: "result_pg_old_data_dir_stat.stat.exists"
  40. - name: Ensure new Postgres data path exists
  41. ansible.builtin.file:
  42. path: "{{ matrix_postgres_data_path }}"
  43. state: directory
  44. mode: 0700
  45. owner: "{{ matrix_user_username }}"
  46. group: "{{ matrix_user_groupname }}"
  47. when: "result_pg_old_data_dir_stat.stat.exists"
  48. - when: "result_pg_old_data_dir_stat.stat.exists"
  49. block:
  50. - name: Relocate Postgres data files from old directory to new
  51. ansible.builtin.command:
  52. cmd: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path | basename }}"
  53. with_items: "{{ result_pg_old_data_dir_find.files }}"
  54. register: matrix_postgres_migrate_postgres_data_directory_move_result
  55. changed_when: matrix_postgres_migrate_postgres_data_directory_move_result.rc == 0
  56. # Intentionally not starting matrix-postgres here.
  57. # It likely needs to be updated to point to the new directory.
  58. # In fact, let's even get rid of the outdated service, to ensure no one will start it
  59. # and have it initialize a new database.
  60. - name: Ensure outdated matrix-postgres.service doesn't exist
  61. ansible.builtin.file:
  62. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postgres.service"
  63. state: absent
  64. when: "result_pg_old_data_dir_stat.stat.exists"
  65. - name: Ensure systemd reloaded after getting rid of outdated matrix-postgres.service
  66. ansible.builtin.service:
  67. daemon_reload: true
  68. when: "result_pg_old_data_dir_stat.stat.exists"