diff --git a/defaults/main.yml b/defaults/main.yml index a0146a5..056f268 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,4 @@ ---- + postgres_ha_service_name: 'postgres-ha' postgres_ha_service_path: '/docker/{{ postgres_ha_service_name }}' postgres_ha_compose_file: '{{ postgres_ha_service_path }}/docker-compose.yml' @@ -8,6 +8,7 @@ postgres_ha_cont_data_vol: '{{ postgres_ha_service_path }}/data' postgres_ha_cont_init_vol: '{{ postgres_ha_service_path }}/init' postgres_ha_cont_backup_vol: '{{ postgres_ha_service_path }}/backup' postgres_ha_cont_image: 'postgres:15.1-alpine' +postgres_ha_cont_networks: [] postgres_ha_cont_port: 5432 postgres_ha_cont_uid: 70 postgres_ha_host_uid: '{{ 100000 + postgres_ha_cont_uid | int }}' diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index 5ca09c5..5c0a5b3 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -14,6 +14,9 @@ services: {% endif %} # This fixes chmod errors on DB startup due to volume + userns-remap PGDATA: '/var/lib/postgresql/data/pgdata' +{% if postgres_ha_cont_networks %} + networks: {{ postgres_ha_cont_networks | to_json }} +{% endif %} ports: - '{{ postgres_ha_cont_port }}:{{ postgres_ha_cont_port }}' tmpfs: @@ -33,3 +36,11 @@ services: '-p', '{{ postgres_ha_cont_port }}', '-U', '{{ postgres_ha_admin_user }}' ] + +{% if postgres_ha_cont_networks != [] %} +networks: +{% for network in postgres_ha_cont_networks %} + {{ network }}: + external: true +{% endfor %} +{% endif %}