This repository provides an Ansible-based automation for deploying a highly available PostgreSQL cluster using Patroni, etcd, and ProxySQL. It is designed for production-grade PostgreSQL clusters with automated failover and load balancing.
- Automated deployment of PostgreSQL HA cluster
- Patroni for PostgreSQL high availability and failover
- etcd for distributed consensus and configuration
- ProxySQL for load balancing
- Secure password management via Ansible variables
- Customizable cluster and network settings
├── inventory.yml # Ansible inventory file
├── site.yml # Main playbook
├── group_vars/
│ └── all.yml # Global variables (PostgreSQL, authentication, etc.)
├── roles/
│ ├── common/ # Common setup tasks
│ ├── patroni/ # Patroni installation and configuration
│ ├── postgres/ # PostgreSQL installation and configuration
│ ├── proxysql/ # ProxySQL installation and configuration
│ └── verify/ # Cluster verification tasks
├── test_cluster.sh # Script to test cluster status
├── test_failover.sh # Script to test failover
└── readme.md # This file
- Clone the repository:
git clone <this-repo-url> cd ansible-postgres-ha
- Configure your inventory:
- Edit
inventory.ymlto define your cluster nodes and their variables.
- Edit
- Set variables:
- Edit
group_vars/all.ymlfor cluster-wide settings (PostgreSQL version, passwords, etc).
- Edit
- Run the playbook:
ansible-playbook -i inventory.yml site.yml
- Test the cluster:
- Use
test_cluster.shandtest_failover.shto verify deployment and failover.
- Use
- Passwords:
- Default passwords are set in
group_vars/all.yml. Change these before deploying to production or making the repository public. - Consider using Ansible Vault to encrypt sensitive variables (passwords, secrets).
- Default passwords are set in
- Inventory:
- Do not commit real IP addresses or sensitive hostnames to the public repository.
- Secrets:
- Remove or encrypt any secrets, tokens, or private keys before publishing.
- Access Control:
- Ensure only trusted users have access to your Ansible control node and inventory.
- Change all default passwords in
group_vars/all.yml. - Remove or anonymize inventory files (
inventory.yml) if they contain real infrastructure details. - Use Ansible Vault for all sensitive variables.
- Review all scripts and playbooks for hardcoded secrets or sensitive data.
Specify your license here (e.g., MIT, Apache 2.0, etc).
Maintainer: Your Name ([email protected])