{"id":40990985,"url":"https://github.com/rom8726/ansible-patroni","last_synced_at":"2026-01-22T07:40:02.733Z","repository":{"id":289978088,"uuid":"973015828","full_name":"rom8726/ansible-patroni","owner":"rom8726","description":"Ansible playbook for deploy PostgreSQL Patroni cluster with HAProxy and metrics","archived":false,"fork":false,"pushed_at":"2025-05-11T04:53:28.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-11T05:24:55.413Z","etag":null,"topics":["ansible","haproxy","keepalived","metrics","patroni","pgbouncer","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rom8726.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-26T04:39:59.000Z","updated_at":"2025-05-11T04:53:32.000Z","dependencies_parsed_at":"2025-05-11T05:32:35.491Z","dependency_job_id":null,"html_url":"https://github.com/rom8726/ansible-patroni","commit_stats":null,"previous_names":["rom8726/ansible-patroni"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rom8726/ansible-patroni","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rom8726%2Fansible-patroni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rom8726%2Fansible-patroni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rom8726%2Fansible-patroni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rom8726%2Fansible-patroni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rom8726","download_url":"https://codeload.github.com/rom8726/ansible-patroni/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rom8726%2Fansible-patroni/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28658109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","haproxy","keepalived","metrics","patroni","pgbouncer","postgresql"],"created_at":"2026-01-22T07:40:02.429Z","updated_at":"2026-01-22T07:40:02.716Z","avatar_url":"https://github.com/rom8726.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansible-patroni\nAnsible playbook for deploying PostgreSQL Patroni cluster\n\n[![boosty-cozy](https://gideonwhite1029.github.io/badges/cozy-boosty_vector.svg)](https://boosty.to/dev-tools-hacker)\n\n⚠️ **WARNING: This configuration is for testing/development purposes only. DO NOT use in production without proper security hardening!**\n\n## Overview\nThis Ansible playbook automates the deployment of a PostgreSQL high-availability cluster using Patroni and etcd. The setup includes the following components for connection management and high availability:\n- `Keepalived` creates a Virtual IP (VIP) for failover.\n- `HAProxy` acts as a proxy layer for distributing requests.\n- `PgBouncer` operates as a connection pooler.\n  \nThe connection path:\n```\nClient -\u003e Keepalived VIP -\u003e HAProxy -\u003e PgBouncer -\u003e PostgreSQL\n```\n\n## Prerequisites\n- Ubuntu/Debian-based system\n- Ansible installed on the control node\n- Network connectivity between all nodes\n\n## Components\n- PostgreSQL 16\n- Patroni\n- etcd (for distributed configuration)\n- PgBouncer (for connection pooling)\n- Keepalived (for VIP)\n- HAProxy (for load balancing)\n- Python 3 and pip\n- Node Exporter (system metrics)\n- Postgres Exporter (PostgreSQL metrics)\n\n## Quick Start\n1. Clone this repository.\n2. Create config files with the command `make init`.\n3. Update `inventory.ini` with your servers:\n```ini\n[promoters]\npatroni1 ansible_host=192.168.64.2 node_id=1\npatroni2 ansible_host=192.168.64.3 node_id=2\npatroni3 ansible_host=192.168.64.4 node_id=3 \n```\n4. Update `ansible.cfg` with your user (root by default).\n5. Set variable `cluster_vip_1` in group_vars (some VIP address for keepalived).\n6. Set variable `keepalived_vip_interface` in keepalived default vars.\n7. Run the playbook:\n```shell\n# Deploy Patroni cluster\nmake up\n```\n\n## Default Configuration\n\n### Network Ports\n- PostgreSQL: 5432\n- Patroni API: 8008\n- etcd client: 2379\n- etcd peer: 2380\n- HAProxy PostgreSQL (master): 5000\n- HAProxy PostgreSQL (replica): 5001\n- HAProxy Statistics: 7000\n- PgBouncer: 6432\n- Node Exporter: 9100\n- Postgres Exporter: 9187\n\n### Keepalived Configuration\n- VIP: Used for automatic failover between HAProxy instances.\n- Configured to determine the `MASTER` node based on its `node_id` in the cluster.\n\n### PgBouncer Configuration\n- Connection pooling for PostgreSQL to reduce the overhead of establishing frequent connections.\n- Default port: `6432`.\n- Authentication method: Userlist file.\n- Configurations stored in `/etc/pgbouncer/pgbouncer.ini`.\n\n### PostgreSQL Settings\n- Version: 16\n- Encoding: UTF8\n- Max Connections: 100\n- Shared Buffers: 256MB\n- WAL Level: replica\n- Shared Preload Libraries: pg_stat_statements, auto_explain\n\n### Patroni Settings\n- TTL: 30\n- Loop Wait: 10\n- Retry Timeout: 10\n- Max Lag: 1048576\n- Uses pg_rewind: true\n- Uses replication slots: true\n\n### Authentication (Default)\n⚠️ Change these values:\n- PostgreSQL superuser: postgres/password\n- Replication user: replicator/password\n\n### Monitoring Components\n#### Node Exporter\n- Version: 1.9.1\n- Metrics Port: 9100\n- Systemd Service: node_exporter.service\n- User: node_exporter\n\n#### Postgres Exporter\n- Version: 0.17.1\n- Metrics Port: 9187\n- Systemd Service: postgres_exporter.service\n- User: postgres\n- Config Path: /etc/postgres_exporter/postgres_exporter.yaml\n\n## Important Security Notes\nThis deployment includes several configurations that are NOT suitable for production:\n- Basic default passwords\n- Non-encrypted connections\n- Root SSH access\n- No SSL/TLS configuration\n- No firewall setup\n- Basic authentication methods\n\n## Logging\n- Patroni logs: /var/log/patroni/patroni.log\n- etcd logs: /var/log/etcd.log\n- PgBouncer logs: /var/log/pgbouncer/pgbouncer.log\n- Log rotation is configured for Patroni logs (7 days retention)\n- Node Exporter logs: journalctl -u node_exporter\n- Postgres Exporter logs: journalctl -u postgres_exporter\n- Keepalived logs: journalctl -u keepalived\n\n## Service Management\n``` bash\n# Patroni service\nsystemctl status patroni\nsystemctl start patroni\nsystemctl stop patroni\n\n# etcd service\nsystemctl status etcd\nsystemctl start etcd\nsystemctl stop etcd\n\n# HAProxy service\nsystemctl status haproxy\nsystemctl start haproxy\nsystemctl stop haproxy\n\n# PgBouncer service\nsystemctl status pgbouncer\nsystemctl start pgbouncer\nsystemctl stop pgbouncer\n\n# Keepalived service\nsystemctl status keepalived\nsystemctl start keepalived\nsystemctl stop keepalived\n\n# Monitoring services\nsystemctl status node_exporter\nsystemctl status postgres_exporter\n```\n\n## Monitoring\n### Available Metrics\n- System metrics (via node_exporter): http://host:9100/metrics\n- PostgreSQL metrics (via postgres_exporter): http://host:9187/metrics\n\n### PostgreSQL Exporter Metrics\nPostgres Exporter provides the following metric groups:\n\n#### PostgreSQL Settings\n- Monitors PostgreSQL configuration parameters\n- Collects values from all pg_settings entries\n- Includes parameter name, value, unit, and a short description\n- Exposed as GAUGE metrics\n\n#### Replication Status\n- Instance replication status monitoring:\n  - Master/replica state detection\n  - Master status monitoring (is_master metric)\n  - Replica status monitoring (is_replica metric)\n  - Replication lag monitoring in seconds (lag_seconds metric)\n  - All metrics are exposed as a GAUGE type\n\n#### Connection Statistics\n- Detailed connection statistics:\n  - Number of connections by state (active, idle, etc.)\n  - Grouped by wait event types\n  - Total connection count monitoring by different states\n  - Exposed as GAUGE metrics with state and wait_event_type labels\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2From8726%2Fansible-patroni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2From8726%2Fansible-patroni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2From8726%2Fansible-patroni/lists"}