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.
 
 

96 lines
3.6 KiB

  1. ---
  2. #
  3. # Generic tasks, no matter what kind of server we're using (internal/external)
  4. #
  5. - import_tasks: tasks/util/detect_existing_postgres_version.yml
  6. # If we have found an existing version (installed from before), we use its corresponding Docker image.
  7. # If not, we install using the latest Postgres.
  8. #
  9. # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
  10. - set_fact:
  11. 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 }}"
  12. - name: Warn if on an old version of Postgres
  13. debug:
  14. 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"
  15. when: "matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
  16. # Even if we don't run the internal server, we still need this for running the CLI
  17. - name: Ensure postgres Docker image is pulled
  18. docker_image:
  19. name: "{{ matrix_postgres_docker_image_to_use }}"
  20. - name: Ensure Postgres environment variables file created
  21. template:
  22. src: "{{ role_path }}/templates/env/{{ item }}.j2"
  23. dest: "{{ matrix_environment_variables_data_path }}/{{ item }}"
  24. mode: 0640
  25. with_items:
  26. - "env-postgres-pgsql-docker"
  27. - "env-postgres-server-docker"
  28. - name: Ensure matrix-postgres-cli script created
  29. template:
  30. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
  31. dest: "/usr/local/bin/matrix-postgres-cli"
  32. mode: 0750
  33. - name: Ensure matrix-make-user-admin script created
  34. template:
  35. src: "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
  36. dest: "/usr/local/bin/matrix-make-user-admin"
  37. mode: 0750
  38. #
  39. # Tasks related to setting up an internal postgres server
  40. #
  41. - name: Ensure postgres data path exists
  42. file:
  43. path: "{{ matrix_postgres_data_path }}"
  44. state: directory
  45. mode: 0700
  46. owner: "{{ matrix_user_username }}"
  47. group: "{{ matrix_user_username }}"
  48. when: "not matrix_postgres_use_external"
  49. - name: Ensure matrix-postgres.service installed
  50. template:
  51. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  52. dest: "/etc/systemd/system/matrix-postgres.service"
  53. mode: 0644
  54. when: "not matrix_postgres_use_external"
  55. #
  56. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  57. #
  58. - name: Check existence of matrix-postgres service
  59. stat: path="/etc/systemd/system/matrix-postgres.service"
  60. register: matrix_postgres_service_stat
  61. when: matrix_postgres_use_external
  62. - name: Ensure matrix-postgres is stopped
  63. service: name=matrix-postgres state=stopped daemon_reload=yes
  64. when: "matrix_postgres_use_external and matrix_postgres_service_stat.stat.exists"
  65. - name: Ensure matrix-postgres.service doesn't exist
  66. file:
  67. path: "/etc/systemd/system/matrix-postgres.service"
  68. state: absent
  69. when: "matrix_postgres_use_external and matrix_postgres_service_stat.stat.exists"
  70. - name: Check existence of matrix-postgres local data path
  71. stat: path="{{ matrix_postgres_data_path }}"
  72. register: matrix_postgres_data_path_stat
  73. when: matrix_postgres_use_external
  74. # We just want to notify the user. Deleting data is too destructive.
  75. - name: Notify if matrix-postgres local data remains
  76. debug:
  77. 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 that."
  78. when: "matrix_postgres_use_external and matrix_postgres_data_path_stat.stat.exists"