HTTPS SSH

Ansible playbook for a fault tolerant PostgreSQL cluster using repmgr and barman.

MORE ABOUT CLUSTER

Tesed on Debian 9, Ansible 2.2.1.0.

Installation

1) Prepare environment

apt install ansible
ssh-keygen -b 2048 -t rsa -N "" -C "root@ansible"
ssh-copy-id root@db1_host
ssh-copy-id root@db2_host
ssh-copy-id root@backup_host

2) Change IPs inside hosts file.

3) Run:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml

Advanced

Install PostgreSQL on db hosts:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg"

All above + join db hosts using OpenVPN:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg,link_dbs"

All above + configure asynchronous replication using repmgr:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg,link_dbs,repmgr"

All above + join all servers using OpenVPN:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg,link_dbs,repmgr,link_all"

All above + configure auto-failover using repmgr daemons and install test PostgreSQL instance on backup host:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg,link_dbs,repmgr,link_all,repmgrd"

All above + configure HA using repmgr daemons events:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml --tags "pg,link_dbs,repmgr,link_all,repmgrd,repmgrd_ha"

All above + configure barman and change replication between db servers to synchronous:

ansible-playbook -i hosts --extra-vars="@vars.yml" main.yml

Vars

host_vars/db1
host_vars/db2
host_vars/backup
vars.yml