####################################
# Auto generated by Ansible:
# ./infra.yml -t pgsvc
####################################

####################################
# PGSQL CMDB
####################################
[meta]
host=127.0.0.1
port=5432
dbname=meta
user={{ pg_admin_username|default('dbuser_dba') }}
password={{ pg_admin_password|default('DBUser.DBA') }}

####################################
# PGSQL Databases
####################################
{% for ip,ins in hostvars.items() %}
{% if ins.pg_cluster is defined and ins.pg_cluster != '' and pg_role is defined and pg_seq is defined %}
{% if ins.pg_role == 'primary' %}
# cluster: {{ ins.pg_cluster }}
[{{ ins.pg_cluster }}]
{% if ins.dns_enabled|default(true) %}
host={{ ins.pg_cluster +  pg_dns_suffix|default('') }}
{% elif ins.pg_vip_enabled|default(false) %}
host={{ ins.pg_vip_address.split('/')[0] }}
{% else %}
host={{ ins.pg_primary_ip|default(ins.inventory_hostname) }}
{% endif %}
port={{ ins.pg_port|default(5432) }}
user={{ ins.pg_admin_username|default('dbuser_dba') }}
password={{ ins.pg_admin_password|default('DBUser.DBA') }}
dbname={{ ins.pg_primary_db|default('postgres') }}

{% endif %}
{% if ins.pg_role == 'primary' and 'pg_databases' in ins %}
{% for database in ins.pg_databases %}
# database: {{ ins.pg_cluster }}-{{ ins.pg_seq }}.{{ database.name }}
[{{ ins.pg_cluster }}.{{ database.name }}]
host={{ ins.inventory_hostname }}
port={{ ins.pg_port|default(5432) }}
user={{ ins.pg_admin_username|default('dbuser_dba') }}
password={{ ins.pg_admin_password|default('DBUser.DBA') }}
dbname={{ database.name }}

{% endfor %}
{% endif %}
# instance: {{ ins.pg_cluster }}-{{ ins.pg_seq }} @ {{ ins.inventory_hostname }}
[{{ ins.pg_cluster }}-{{ ins.pg_seq }}]
host={{ ins.inventory_hostname }}
port={{ ins.pg_port|default(5432) }}
user={{ ins.pg_admin_username|default('dbuser_dba') }}
password={{ ins.pg_admin_password|default('DBUser.DBA') }}
dbname={{ ins.pg_primary_db|default('postgres') }}
{% endif %}

{% endfor %}