Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

74 строки
3.0 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. # A tmpfs, because the database is thrown away with the container and not writing it
  46. # to the overlay filesystem is faster. Mounted at /var/lib/postgresql rather than at
  47. # .../data: since 18 the image puts PGDATA in a versioned subdirectory and refuses to
  48. # start if it finds a mount at the old path.
  49. - --tmpfs=/var/lib/postgresql
  50. - "{{ molecule_shared_image_postgres }}"
  51. register: molecule_shared_postgres_start
  52. changed_when: molecule_shared_postgres_start.rc == 0
  53. # `pg_isready` needs the username: it defaults to the OS user of whoever runs it, which inside
  54. # this container is `postgres` and may not be the role the scenario created.
  55. - name: Wait for Postgres to accept connections
  56. ansible.builtin.command:
  57. argv:
  58. - docker
  59. - exec
  60. - "{{ molecule_shared_postgres_name | default('matrix-postgres-molecule') }}"
  61. - pg_isready
  62. - --username={{ molecule_shared_postgres_username }}
  63. - --dbname={{ molecule_shared_postgres_database }}
  64. - --quiet
  65. register: molecule_shared_postgres_ready
  66. changed_when: false
  67. until: molecule_shared_postgres_ready.rc == 0
  68. retries: 30
  69. delay: 2