From a38d2c707a8ac3c0deada9c039a6d8c4bc65f2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 21 Nov 2023 16:15:43 +0100 Subject: [PATCH] config: add admin.sh wrapper script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- tasks/config.yml | 14 +++++++++----- tasks/start.yml | 8 ++++++++ templates/scripts/admin.sh.j2 | 10 ++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 templates/scripts/admin.sh.j2 diff --git a/tasks/config.yml b/tasks/config.yml index 93a1958..9cb9943 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -23,10 +23,14 @@ with_fileglob: - 'templates/init/*.sql' -- name: 'Create compose file' +- name: Install PostgreSQL client + apt: + name: 'postgresql-client' + +- name: Create Admin wrapper script template: - src: 'docker-compose.yml.j2' - dest: '{{ postgres_ha_compose_file }}' - owner: 'dockremap' + src: 'scripts/admin.sh.j2' + dest: '{{ postgres_ha_service_path }}/admin.sh' + owner: 'root' group: 'docker' - mode: 0644 + mode: 0750 diff --git a/tasks/start.yml b/tasks/start.yml index a54dd27..fa465df 100644 --- a/tasks/start.yml +++ b/tasks/start.yml @@ -1,4 +1,12 @@ --- +- name: 'Create compose file' + template: + src: 'docker-compose.yml.j2' + dest: '{{ postgres_ha_compose_file }}' + owner: 'dockremap' + group: 'docker' + mode: 0644 + - name: 'Create database container' docker_compose: project_src: '{{ postgres_ha_service_path }}' diff --git a/templates/scripts/admin.sh.j2 b/templates/scripts/admin.sh.j2 new file mode 100644 index 0000000..ab03790 --- /dev/null +++ b/templates/scripts/admin.sh.j2 @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# vim: set ft=sh: +set -Eeo pipefail +export PGPASSWORD='{{ postgres_ha_admin_pass }}' +exec psql \ + --host='127.0.0.1' \ + --port='{{ postgres_ha_cont_port }}' \ + --username='{{ postgres_ha_admin_user }}' \ + --dbname='{{ postgres_ha_db_name }}' \ + ${@}