Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

115 lines
4.1 KiB

  1. ---
  2. #
  3. # Generic tasks, no matter what kind of server we're using (internal/external)
  4. #
  5. - import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
  6. when: matrix_postgres_enabled
  7. - import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
  8. when: matrix_postgres_enabled
  9. # If we have found an existing version (installed from before), we use its corresponding Docker image.
  10. # If not, we install using the latest Postgres.
  11. #
  12. # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
  13. - set_fact:
  14. matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}"
  15. when: matrix_postgres_enabled
  16. - name: Warn if on an old version of Postgres
  17. debug:
  18. msg: "NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres"
  19. when: "matrix_postgres_enabled and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
  20. # Even if we don't run the internal server, we still need this for running the CLI
  21. - name: Ensure postgres Docker image is pulled
  22. docker_image:
  23. name: "{{ matrix_postgres_docker_image_to_use }}"
  24. when: matrix_postgres_enabled
  25. # We always create these directories, even if an external Postgres is used,
  26. # because we store environment variable files there.
  27. - name: Ensure Postgres paths exist
  28. file:
  29. path: "{{ item }}"
  30. state: directory
  31. mode: 0700
  32. owner: "{{ matrix_user_username }}"
  33. group: "{{ matrix_user_username }}"
  34. with_items:
  35. - "{{ matrix_postgres_base_path }}"
  36. - "{{ matrix_postgres_data_path }}"
  37. when: matrix_postgres_enabled
  38. - name: Ensure Postgres environment variables file created
  39. template:
  40. src: "{{ role_path }}/templates/{{ item }}.j2"
  41. dest: "{{ matrix_postgres_base_path }}/{{ item }}"
  42. mode: 0640
  43. with_items:
  44. - "env-postgres-psql"
  45. - "env-postgres-server"
  46. when: matrix_postgres_enabled
  47. - name: Ensure matrix-postgres-cli script created
  48. template:
  49. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
  50. dest: "/usr/local/bin/matrix-postgres-cli"
  51. mode: 0750
  52. when: matrix_postgres_enabled
  53. - name: Ensure matrix-make-user-admin script created
  54. template:
  55. src: "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
  56. dest: "/usr/local/bin/matrix-make-user-admin"
  57. mode: 0750
  58. when: matrix_postgres_enabled
  59. #
  60. # Tasks related to setting up an internal postgres server
  61. #
  62. - name: Ensure matrix-postgres.service installed
  63. template:
  64. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  65. dest: "/etc/systemd/system/matrix-postgres.service"
  66. mode: 0644
  67. when: matrix_postgres_enabled
  68. #
  69. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  70. #
  71. - name: Check existence of matrix-postgres service
  72. stat:
  73. path: "/etc/systemd/system/matrix-postgres.service"
  74. register: matrix_postgres_service_stat
  75. when: "not matrix_postgres_enabled"
  76. - name: Ensure matrix-postgres is stopped
  77. service:
  78. name: matrix-postgres
  79. state: stopped
  80. daemon_reload: yes
  81. when: "not matrix_postgres_enabled and matrix_postgres_service_stat.stat.exists"
  82. - name: Ensure matrix-postgres.service doesn't exist
  83. file:
  84. path: "/etc/systemd/system/matrix-postgres.service"
  85. state: absent
  86. when: "not matrix_postgres_enabled and matrix_postgres_service_stat.stat.exists"
  87. - name: Check existence of matrix-postgres local data path
  88. stat:
  89. path: "{{ matrix_postgres_data_path }}"
  90. register: matrix_postgres_data_path_stat
  91. when: "not matrix_postgres_enabled"
  92. # We just want to notify the user. Deleting data is too destructive.
  93. - name: Notify if matrix-postgres local data remains
  94. debug:
  95. msg: "Note: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it."
  96. when: "not matrix_postgres_enabled and matrix_postgres_data_path_stat.stat.exists"