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.
 
 

42 lines
2.0 KiB

  1. ---
  2. # It'd be better if this is belonged to `validate_config.yml`, but it would have to be some loop-within-a-loop there,
  3. # and that's ugly. We also don't expect this to catch errors often. It's more of a defensive last-minute check.
  4. - name: Fail if additional database data appears invalid
  5. ansible.builtin.fail:
  6. msg: "Additional database definition ({{ additional_db }} lacks a required key: {{ item }}"
  7. when: "item not in additional_db"
  8. with_items: "{{ ['name', 'username', 'password'] }}"
  9. # The SQL statements that we'll run against Postgres are stored in a file that others can't read.
  10. # This file will be mounted into the container and fed to Postgres.
  11. # This way, we avoid passing sensitive data around in CLI commands that other users on the system can see.
  12. - name: Create additional database initialization SQL file for {{ additional_db.name }}
  13. ansible.builtin.template:
  14. src: "{{ role_path }}/templates/sql/init-additional-db-user-and-role.sql.j2"
  15. dest: "/tmp/matrix-postgres-init-additional-db-user-and-role.sql"
  16. mode: 0600
  17. owner: "{{ matrix_user_uid }}"
  18. group: "{{ matrix_user_gid }}"
  19. - name: Execute Postgres additional database initialization SQL file for {{ additional_db.name }}
  20. ansible.builtin.command:
  21. cmd: >-
  22. {{ matrix_host_command_docker }} run
  23. --rm
  24. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  25. --cap-drop=ALL
  26. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql
  27. --network {{ matrix_docker_network }}
  28. --mount type=bind,src=/tmp/matrix-postgres-init-additional-db-user-and-role.sql,dst=/matrix-postgres-init-additional-db-user-and-role.sql,ro
  29. --entrypoint=/bin/sh
  30. {{ matrix_postgres_docker_image_to_use }}
  31. -c
  32. 'psql -h {{ matrix_postgres_connection_hostname }} --file=/matrix-postgres-init-additional-db-user-and-role.sql'
  33. changed_when: true
  34. - name: Delete additional database initialization SQL file for {{ additional_db.name }}
  35. ansible.builtin.file:
  36. path: /tmp/matrix-postgres-init-additional-db-user-and-role.sql
  37. state: absent