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.
 
 

76 lines
4.0 KiB

  1. ---
  2. # This utility aims to determine if there is some existing Postgres version in use or not.
  3. # If there is, it also tries to detect the Docker image that corresponds to that version.
  4. #
  5. # This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible
  6. # to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html
  7. - name: Fail detection if expectation fails (Postgres not enabled)
  8. ansible.builtin.fail:
  9. msg: "Trying to detect the version of the built-in Postgres server, but Postgres installation is not enabled (`matrix_postgres_enabled: false`)"
  10. when: not matrix_postgres_enabled
  11. - name: Initialize Postgres version determination variables (default to empty)
  12. ansible.builtin.set_fact:
  13. matrix_postgres_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION"
  14. matrix_postgres_detected_existing: false
  15. matrix_postgres_detected_version: ""
  16. matrix_postgres_detected_version_corresponding_docker_image: ""
  17. - name: Determine existing Postgres version (check PG_VERSION file)
  18. ansible.builtin.stat:
  19. path: "{{ matrix_postgres_detection_pg_version_path }}"
  20. register: result_pg_version_stat
  21. - ansible.builtin.set_fact:
  22. matrix_postgres_detected_existing: true
  23. when: "result_pg_version_stat.stat.exists"
  24. - name: Determine existing Postgres version (read PG_VERSION file)
  25. ansible.builtin.slurp:
  26. src: "{{ matrix_postgres_detection_pg_version_path }}"
  27. register: result_pg_version
  28. when: matrix_postgres_detected_existing | bool
  29. - name: Determine existing Postgres version (make sense of PG_VERSION file)
  30. ansible.builtin.set_fact:
  31. matrix_postgres_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}"
  32. when: matrix_postgres_detected_existing | bool
  33. - name: Determine corresponding Docker image to detected version (assume default of latest)
  34. ansible.builtin.set_fact:
  35. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_latest }}"
  36. when: "matrix_postgres_detected_version != ''"
  37. - name: Determine corresponding Docker image to detected version (use 9.x, if detected)
  38. ansible.builtin.set_fact:
  39. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v9 }}"
  40. when: "matrix_postgres_detected_version.startswith('9.')"
  41. - name: Determine corresponding Docker image to detected version (use 10.x, if detected)
  42. ansible.builtin.set_fact:
  43. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v10 }}"
  44. when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')"
  45. - name: Determine corresponding Docker image to detected version (use 11.x, if detected)
  46. ansible.builtin.set_fact:
  47. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v11 }}"
  48. when: "matrix_postgres_detected_version == '11' or matrix_postgres_detected_version.startswith('11.')"
  49. - name: Determine corresponding Docker image to detected version (use 12.x, if detected)
  50. ansible.builtin.set_fact:
  51. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v12 }}"
  52. when: "matrix_postgres_detected_version == '12' or matrix_postgres_detected_version.startswith('12.')"
  53. - name: Determine corresponding Docker image to detected version (use 13.x, if detected)
  54. ansible.builtin.set_fact:
  55. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v13 }}"
  56. when: "matrix_postgres_detected_version == '13' or matrix_postgres_detected_version.startswith('13.')"
  57. - name: Determine corresponding Docker image to detected version (use 14.x, if detected)
  58. ansible.builtin.set_fact:
  59. matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v14 }}"
  60. when: "matrix_postgres_detected_version == '14' or matrix_postgres_detected_version.startswith('14.')"