Matrix Docker Ansible eploy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

79 linhas
3.3 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. # Stands up Postgres on a container network, for scenarios whose role has a database.
  6. #
  7. # Include from a scenario's prepare.yml:
  8. #
  9. # - name: Ensure Postgres is running
  10. # ansible.builtin.include_tasks:
  11. # file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/tasks/postgres.yml"
  12. # vars:
  13. # molecule_shared_postgres_network: "{{ <role>_container_network }}"
  14. # molecule_shared_postgres_database: matrix_<role>
  15. # molecule_shared_postgres_username: matrix_<role>
  16. # molecule_shared_postgres_password: <something>
  17. #
  18. # The role should then be pointed at it with its own `_database_engine: postgres` and
  19. # `_database_hostname: matrix-postgres-molecule` (or whatever hostname is passed here).
  20. #
  21. # This is what the playbook does in a real run: `group_vars/matrix_servers` selects postgres
  22. # whenever postgres is enabled, which is the default. sqlite is the path almost nobody uses.
  23. - name: Ensure a previous Postgres is gone
  24. ansible.builtin.command:
  25. argv:
  26. - docker
  27. - rm
  28. - --force
  29. - "{{ molecule_shared_postgres_name | default('matrix-postgres-molecule') }}"
  30. register: molecule_shared_postgres_removal
  31. changed_when: molecule_shared_postgres_removal.rc == 0
  32. failed_when: false
  33. - name: Ensure Postgres is running
  34. ansible.builtin.command:
  35. argv:
  36. - docker
  37. - run
  38. - --detach
  39. - --name={{ molecule_shared_postgres_name | default('matrix-postgres-molecule') }}
  40. - --network={{ molecule_shared_postgres_network }}
  41. - --network-alias={{ molecule_shared_postgres_hostname | default('matrix-postgres-molecule') }}
  42. - --env=POSTGRES_DB={{ molecule_shared_postgres_database }}
  43. - --env=POSTGRES_USER={{ molecule_shared_postgres_username }}
  44. - --env=POSTGRES_PASSWORD={{ molecule_shared_postgres_password }}
  45. # PGDATA is set explicitly, and to /data rather than anywhere under
  46. # /var/lib/postgresql, for the same reasons the postgres role does it: v18 changed the
  47. # default to a versioned subdirectory, and /var/lib/postgresql is a VOLUME in the image,
  48. # so nothing can be mounted beneath it. Setting it explicitly also means a future image
  49. # changing its own default cannot move the data out from under this.
  50. #
  51. # A tmpfs, because the database is thrown away with the container and not writing it to
  52. # the overlay filesystem is faster.
  53. - --env=PGDATA=/data
  54. - --tmpfs=/data
  55. - "{{ molecule_shared_image_postgres }}"
  56. register: molecule_shared_postgres_start
  57. changed_when: molecule_shared_postgres_start.rc == 0
  58. # `pg_isready` needs the username: it defaults to the OS user of whoever runs it, which inside
  59. # this container is `postgres` and may not be the role the scenario created.
  60. - name: Wait for Postgres to accept connections
  61. ansible.builtin.command:
  62. argv:
  63. - docker
  64. - exec
  65. - "{{ molecule_shared_postgres_name | default('matrix-postgres-molecule') }}"
  66. - pg_isready
  67. - --username={{ molecule_shared_postgres_username }}
  68. - --dbname={{ molecule_shared_postgres_database }}
  69. - --quiet
  70. register: molecule_shared_postgres_ready
  71. changed_when: false
  72. until: molecule_shared_postgres_ready.rc == 0
  73. retries: 30
  74. delay: 2