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.
 
 

140 lines
5.3 KiB

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