AMQ Streams KRaft Role
This role orchestrates the initialization and configuration of Apache Kafka in KRaft (Kafka Raft Metadata) mode, removing the traditional dependency on ZooKeeper. It handles the mandatory bootstrapping process by generating a unique Cluster UUID (if not provided) and executing kafka-storage.sh to format the storage directories with the necessary metadata. Additionally, it prepares the critical configuration parameters required for a ZooKeeper-less environment, ensuring the correct setup of process roles, controller quorums, and the strict separation of broker and controller listeners.
Requirements
Role Dependencies:
amq_streams_common(must be run first to install the Kafka binaries).Kafka Version: Designed for Kafka 4.0.0+ or Kafka 3.x with KRaft enabled.
Role Variables
Variable |
Default Value |
Description |
|---|---|---|
|
|
The base directory where AMQ Streams/Kafka is installed. |
|
|
The absolute path to the Kafka installation home directory. |
|
|
The directory containing |
|
|
The directory where Kafka stores its KRaft metadata and log data. |
|
|
The UUID of the Kafka cluster. If left empty, the role will auto-generate a random UUID during the first run. |
|
|
The unique integer ID for this specific broker/controller node. Must be unique per host. |
|
|
Defines the role of this node. Options: |
|
|
The voter connection string in the format |
|
|
The port used for standard Client (broker) traffic. |
|
|
The port used for Controller-to-Controller Raft communication. |
|
(See defaults) |
A list of all listeners to bind. Must include both the Controller and Broker listeners (e.g., |
|
(See defaults) |
A list of listeners advertised to clients. Must ONLY include Broker listeners (e.g., |
|
|
The listener name used by the controller quorum (must match an entry in |
|
|
The listener name used for replication between brokers. |
|
(See defaults) |
A list of |
|
|
The comma-separated list of directories for log data. Usually matches the data dir. |
|
|
The number of hours to keep log segments before deletion (Default: 7 days). |
|
|
Controls whether tasks (like creating directories and formatting storage) run with elevated privileges ( |
|
|
The systemd service name for the KRaft node. |
|
|
The Jinja2 template used to render the server configuration. |
|
|
The Jinja2 template used for the systemd environment file. |
|
|
The path to the systemd environment file on disk. |
|
|
The directory for service log output. |
|
|
Default values to apply to |
|
|
Whether to skip waiting for the listener port to become available. |
|
|
Minimum size of the server log to consider the node running and functional. |
Example Playbook
This role is self-contained and does not require amq_streams_broker. It configures KRaft, formats storage, and starts the Kafka service. For ZooKeeper-based deployments, use amq_streams_broker instead.
---
- hosts: kafka_nodes
roles:
# Install Java and Kafka Binaries
- role: amq_streams_common
# Configure, format storage, and start Kafka
- role: amq_streams_kraft
License
Apache License v2.0 or later