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.
 
 

136 lines
5.3 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|bool
  7. - import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
  8. when: matrix_postgres_enabled|bool
  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|bool
  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|bool 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. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  25. force_source: "{{ matrix_postgres_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  26. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_docker_image_force_pull }}"
  27. when: matrix_postgres_enabled|bool
  28. # We always create these directories, even if an external Postgres is used,
  29. # because we store environment variable files there.
  30. - name: Ensure Postgres paths exist
  31. file:
  32. path: "{{ item }}"
  33. state: directory
  34. mode: 0700
  35. owner: "{{ matrix_user_username }}"
  36. group: "{{ matrix_user_username }}"
  37. with_items:
  38. - "{{ matrix_postgres_base_path }}"
  39. - "{{ matrix_postgres_data_path }}"
  40. when: matrix_postgres_enabled|bool
  41. - name: Ensure Postgres environment variables file created
  42. template:
  43. src: "{{ role_path }}/templates/{{ item }}.j2"
  44. dest: "{{ matrix_postgres_base_path }}/{{ item }}"
  45. mode: 0640
  46. with_items:
  47. - "env-postgres-psql"
  48. - "env-postgres-server"
  49. when: matrix_postgres_enabled|bool
  50. - name: Ensure matrix-postgres-cli script created
  51. template:
  52. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
  53. dest: "/usr/local/bin/matrix-postgres-cli"
  54. mode: 0750
  55. when: matrix_postgres_enabled|bool
  56. - name: Ensure matrix-make-user-admin script created
  57. template:
  58. src: "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
  59. dest: "/usr/local/bin/matrix-make-user-admin"
  60. mode: 0750
  61. when: matrix_postgres_enabled|bool
  62. #
  63. # Tasks related to setting up an internal postgres server
  64. #
  65. - name: Ensure matrix-postgres.service installed
  66. template:
  67. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  68. dest: "/etc/systemd/system/matrix-postgres.service"
  69. mode: 0644
  70. register: matrix_postgres_systemd_service_result
  71. when: matrix_postgres_enabled|bool
  72. - name: Ensure systemd reloaded after matrix-postgres.service installation
  73. service:
  74. daemon_reload: yes
  75. when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
  76. #
  77. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  78. #
  79. - name: Check existence of matrix-postgres service
  80. stat:
  81. path: "/etc/systemd/system/matrix-postgres.service"
  82. register: matrix_postgres_service_stat
  83. when: "not matrix_postgres_enabled|bool"
  84. - name: Ensure matrix-postgres is stopped
  85. service:
  86. name: matrix-postgres
  87. state: stopped
  88. daemon_reload: yes
  89. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  90. - name: Ensure matrix-postgres.service doesn't exist
  91. file:
  92. path: "/etc/systemd/system/matrix-postgres.service"
  93. state: absent
  94. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  95. - name: Ensure systemd reloaded after matrix-postgres.service removal
  96. service:
  97. daemon_reload: yes
  98. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  99. - name: Check existence of matrix-postgres local data path
  100. stat:
  101. path: "{{ matrix_postgres_data_path }}"
  102. register: matrix_postgres_data_path_stat
  103. when: "not matrix_postgres_enabled|bool"
  104. # We just want to notify the user. Deleting data is too destructive.
  105. - name: Notify if matrix-postgres local data remains
  106. debug:
  107. 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."
  108. when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
  109. - name: Ensure matrix-postgres-update-user-password-hash script created
  110. template:
  111. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
  112. dest: "/usr/local/bin/matrix-postgres-update-user-password-hash"
  113. mode: 0750
  114. when: matrix_postgres_enabled|bool