Production-ready Ansible collection for deploying Apache Kafka with KRaft consensus (no ZooKeeper), TLS/SASL security, and a full monitoring stack.
This collection automates the complete lifecycle of an Apache Kafka cluster:
- Apache Kafka with KRaft mode (controllers + brokers)
- TLS encryption with self-signed CA and per-node certificates
- SASL/SCRAM-SHA-512 authentication
- Prometheus metrics collection with Kafka-specific alert rules
- Grafana dashboards for cluster, broker, controller, and JVM monitoring
- Kafbat UI for web-based cluster management
| Role | Description |
|---|---|
common |
OS prerequisites: packages, Java 21, storage, kernel tuning, NTP |
ssl |
TLS certificate generation: self-signed CA, keystores, truststores |
kafka_install |
Apache Kafka binary download, extraction, JMX exporter |
kafka_controller |
KRaft controller deployment with quorum management |
kafka_broker |
Kafka broker deployment with SSL and SASL/SCRAM |
kafka_topics |
Declarative Kafka topic creation and management |
kafka_ui |
Kafbat UI deployment for cluster management |
prometheus |
Prometheus with Kafka scrape targets and alert rules |
grafana |
Grafana with pre-built Kafka dashboards |
kafka_analysis |
Read-only topic configuration analysis and reporting |
- Ansible: >= 2.16.0
- Python: >= 3.10
- Target OS: Ubuntu 20.04+, Debian 11+, RHEL/Rocky 8+
- Java: OpenJDK 21 (installed by the
commonrole)
| Port | Service | Protocol |
|---|---|---|
| 9093 | KRaft Controller | TCP |
| 9092 | Kafka Broker (SSL) | TCP |
| 9094 | Kafka Broker (SASL_SSL) | TCP |
| 7071 | JMX Exporter | TCP |
| 9090 | Prometheus | TCP |
| 3000 | Grafana | TCP |
| 8080 | Kafka UI | TCP |
ansible-galaxy collection install osodevops.kafka_platformOr add to your requirements.yml:
collections:
- name: osodevops.kafka_platform
version: ">=1.0.0"-
Install the collection:
ansible-galaxy collection install osodevops.kafka_platform
-
Copy the example inventory:
cp -r ~/.ansible/collections/ansible_collections/osodevops/kafka_platform/examples/inventory ./inventory -
Customize your inventory:
Edit
inventory/hosts.ymlwith your hostnames and IPs, then update the group_vars files:group_vars/all/main.yml— cluster ID, quorum voters, pathsgroup_vars/all/security.yml— TLS and SCRAM passwords (encrypt withansible-vault)group_vars/all/topics.yml— topic definitionsgroup_vars/all/monitoring.yml— Prometheus targets
-
Deploy the cluster:
ansible-playbook -i inventory/hosts.yml osodevops.kafka_platform.site
-
Verify health:
ansible-playbook -i inventory/hosts.yml osodevops.kafka_platform.health_check
┌─────────────────────────────────┐
│ KRaft Controller Quorum │
│ ┌──────┐ ┌──────┐ ┌──────┐ │
│ │ C-01 │ │ C-02 │ │ C-03 │ │
│ │ :9093│ │ :9093│ │ :9093│ │
│ └──┬───┘ └──┬───┘ └──┬───┘ │
└─────┼────────┼────────┼─────────┘
│ Metadata Replication │
┌─────┼────────┼────────┼─────────┐
│ ┌──┴───┐ ┌──┴───┐ ┌──┴───┐ │
│ │ B-01 │ │ B-02 │ │ B-03 │ │
│ │ :9092│ │ :9092│ │ :9092│ │
│ │ :9094│ │ :9094│ │ :9094│ │
│ └──┬───┘ └──┬───┘ └──┬───┘ │
│ Kafka Broker Fleet │
└─────┬────────┬────────┬─────────┘
│ JMX :7071 │
┌─────┴────────────────────────────┐
│ ┌────────────┐ ┌────────────┐ │
│ │ Prometheus │ │ Grafana │ │
│ │ :9090 │──│ :3000 │ │
│ └────────────┘ │ Kafka UI │ │
│ │ :8080 │ │
│ └────────────┘ │
│ Monitoring Stack │
└──────────────────────────────────┘
- Controllers manage cluster metadata via Raft consensus (KRaft)
- Brokers handle data plane operations (produce/consume)
- JMX Exporter exposes Kafka metrics on each node
- Prometheus scrapes metrics from all Kafka nodes
- Grafana provides dashboards and alerting
See docs/VARIABLES.md for the complete variable reference.
Key configuration files in your inventory:
| File | Purpose |
|---|---|
group_vars/all/main.yml |
Kafka version, paths, cluster ID, quorum voters |
group_vars/all/kafka.yml |
Replication, partitions, retention, networking |
group_vars/all/security.yml |
TLS certificates, SCRAM users and passwords |
group_vars/all/topics.yml |
Topic definitions with per-topic config |
group_vars/all/monitoring.yml |
Prometheus, Grafana, Kafka UI settings |
The ssl role generates a self-signed CA and per-node certificates:
- PKCS12 keystores with SAN (Subject Alternative Name) support
- Mutual TLS (mTLS) between controllers and brokers
- Configurable certificate validity periods
The kafka_broker role configures SASL/SCRAM authentication:
- Per-application SCRAM users with individual credentials
- ACL-based authorization with deny-by-default support
- Super user configuration for administrative access
Important: Encrypt security.yml with ansible-vault in production.
| Playbook | Description |
|---|---|
site.yml |
Full cluster deployment (greenfield/brownfield aware) |
common.yml |
OS prerequisites only |
kafka_controller.yml |
Controller deployment |
kafka_broker.yml |
Broker deployment |
monitoring.yml |
Prometheus + Grafana + Kafka UI |
create_topics.yml |
Topic provisioning |
create_acls.yml |
ACL provisioning |
create_scram_users.yml |
SCRAM user creation |
health_check.yml |
Full cluster health verification |
rolling_restart.yml |
Zero-downtime rolling restart |
upgrade.yml |
Rolling Kafka version upgrade |
analysis.yml |
Topic configuration analysis |
ansible-playbook -i inventory/hosts.yml osodevops.kafka_platform.rolling_restartRestarts controllers first (serial:1), then brokers (serial:1), with health checks between each node.
ansible-playbook -i inventory/hosts.yml osodevops.kafka_platform.upgrade \
-e kafka_new_version=4.1.0Downloads the new version to all nodes, then performs a rolling upgrade with zero-downtime.
ansible-playbook -i inventory/hosts.yml osodevops.kafka_platform.create_topicsCreates topics defined in group_vars/all/topics.yml. Idempotent — skips existing topics.
This collection includes Molecule test scenarios:
# Basic single-node test (PLAINTEXT)
make test
# Multi-node TLS + SCRAM test
make test-tlsRequirements: Docker, Python 3.10+, molecule, molecule-plugins[docker].
- Fork the repository
- Create a feature branch
- Make your changes
- Run
make lintandmake test - Submit a pull request
Apache-2.0 — see LICENSE for details.