-
Notifications
You must be signed in to change notification settings - Fork 7
AMW-162 Add support for KRaft #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hcherukuri
merged 1 commit into
ansible-middleware:main
from
RanabirChakraborty:AMW-162
Dec 16, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --- | ||
| - name: "Automate AMQ Streams KRaft install" | ||
| hosts: all | ||
| vars: | ||
| # Topic Management | ||
| amq_streams_broker_topics: | ||
| - name: sampleTopic | ||
| partitions: 2 | ||
| replication_factor: 1 | ||
| - name: otherTopic | ||
| partitions: 4 | ||
| replication_factor: 1 | ||
| vars_files: | ||
| - vars.yml | ||
| roles: | ||
| - role: amq_streams_common | ||
| - role: amq_streams_kraft | ||
| tasks: | ||
| - name: "Ensure AMQ Streams Broker is running and available." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_broker | ||
| vars: | ||
| amq_streams_common_skip_download: true | ||
|
|
||
| - name: "Ensure AMQ Streams Connect is running and available." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_connect | ||
| vars: | ||
| connectors: | ||
| - { name: "file", path: "connectors/file.yml" } | ||
|
|
||
| - name: "Validate that KRaft deployment is functional." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_kraft | ||
| tasks_from: validate.yml | ||
|
|
||
| - name: "Validate that Broker deployment is functional." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_broker | ||
| tasks_from: validate.yml | ||
|
|
||
| - name: "Validate that Connect deployment is functional." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_connect | ||
| tasks_from: validate.yml | ||
|
|
||
| post_tasks: | ||
| - name: "Ensures topics exist." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_broker | ||
| tasks_from: topic/create.yml | ||
| loop: "{{ amq_streams_broker_topics }}" | ||
| loop_control: | ||
| loop_var: topic | ||
| vars: | ||
| topic_name: "{{ topic.name }}" | ||
| topic_partitions: "{{ topic.partitions }}" | ||
| topic_replication_factor: "{{ topic.replication_factor }}" | ||
|
|
||
| - name: "Describe created topics." | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_broker | ||
| tasks_from: topic/describe.yml | ||
| loop: "{{ amq_streams_broker_topics }}" | ||
| loop_control: | ||
| loop_var: topic | ||
| vars: | ||
| topic_name: "{{ topic.name }}" | ||
|
|
||
| - name: "Delete topics" | ||
| ansible.builtin.include_role: | ||
| name: amq_streams_broker | ||
| tasks_from: topic/delete.yml | ||
| loop: "{{ amq_streams_broker_topics }}" | ||
| loop_control: | ||
| loop_var: topic | ||
| vars: | ||
| topic_name: "{{ topic.name }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| driver: | ||
| name: docker | ||
| platforms: | ||
| - name: instance | ||
| image: registry.access.redhat.com/ubi9/ubi-init:latest | ||
| command: "/usr/sbin/init" | ||
| pre_build_image: true | ||
| privileged: true | ||
| groups: | ||
| - brokers | ||
| provisioner: | ||
| name: ansible | ||
| config_options: | ||
| defaults: | ||
| interpreter_python: auto_silent | ||
| ssh_connection: | ||
| pipelining: false | ||
| playbooks: | ||
| prepare: ../prepare.yml | ||
| converge: converge.yml | ||
| verify: verify.yml | ||
| inventory: | ||
| host_vars: | ||
| localhost: | ||
| ansible_python_interpreter: "{{ ansible_playbook_python }}" | ||
| env: | ||
| ANSIBLE_FORCE_COLOR: "true" | ||
| verifier: | ||
| name: ansible | ||
| scenario: | ||
| test_sequence: | ||
| - cleanup | ||
| - destroy | ||
| - syntax | ||
| - create | ||
| - prepare | ||
| - converge | ||
| - idempotence | ||
| - side_effect | ||
| - verify | ||
| - cleanup | ||
| - destroy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../roles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| amq_streams_common_escalade_privilege_group_create: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_common_escalade_privilege_user_create: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_common_archive_extraction_requires_privilege_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_common_dependencies_require_priv: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_zookeeper_data_require_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_zookeeper_restart_requires_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_broker_tls_truststore_client_require_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_broker_config_files_requires_privilege_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_cruise_control_path_to_capacity_file_require_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_cruise_control_logfiles_requires_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_connect_source_file_require_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_kraft_priv_escalation: "{{ amq_streams_install_requires_become | default(true) }}" | ||
| amq_streams_common_product_version: 4.1.1 | ||
| # Run the Systemd Service as root | ||
| amq_streams_broker_user: root | ||
| amq_streams_broker_group: root | ||
|
|
||
| # Run KRaft tasks as root | ||
| amq_streams_kraft_user: root | ||
| amq_streams_kraft_group: root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| - name: Verify | ||
| hosts: all | ||
| tasks: | ||
|
|
||
| - name: Populate service facts | ||
| ansible.builtin.service_facts: | ||
|
|
||
| - name: Check broker service | ||
| assert: | ||
| that: | ||
| - ansible_facts.services["amq_streams_broker.service"]["state"] == "running" | ||
| - ansible_facts.services["amq_streams_broker.service"]["status"] == "enabled" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # 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 | | ||
| | :--- | :--- | :--- | | ||
| | `amq_streams_install_dir` | `/opt` | The base directory where AMQ Streams/Kafka is installed. | | ||
| | `amq_streams_kafka_home` | `{{ amq_streams_install_dir }}/kafka_{{ amq_streams_common_version }}/` | The absolute path to the Kafka installation home directory. | | ||
| | `amq_streams_kraft_config_dir` | `{{ amq_streams_kafka_home }}/config` | The directory containing `server.properties` and other config files. | | ||
| | `amq_streams_kraft_data_dir` | `{{ amq_streams_kafka_home }}/data/kraft` | The directory where Kafka stores its KRaft metadata and log data. | | ||
| | `amq_streams_cluster_id` | `""` | The UUID of the Kafka cluster. If left empty, the role will auto-generate a random UUID during the first run. | | ||
| | `amq_streams_kraft_node_id` | `1` | The unique integer ID for this specific broker/controller node. **Must be unique per host.** | | ||
| | `amq_streams_kraft_process_roles` | `"broker,controller"` | Defines the role of this node. Options: `broker`, `controller`, or `broker,controller` (combined). | | ||
| | `amq_streams_kraft_controller_quorum_voters` | `1@{{ ansible_host }}:{{ amq_streams_kraft_controller_port }}` | The voter connection string in the format `nodeId@host:port`. Must list all controller nodes in the cluster. | | ||
| | `amq_streams_kraft_listener_port` | `9092` | The port used for standard Client (broker) traffic. | | ||
| | `amq_streams_kraft_controller_port` | `9093` | The port used for Controller-to-Controller Raft communication. | | ||
| | `amq_streams_kraft_listeners` | *(See defaults)* | A list of all listeners to bind. Must include **both** the Controller and Broker listeners (e.g., `PLAINTEXT://...` and `CONTROLLER://...`). | | ||
| | `amq_streams_kraft_advertised_listeners` | *(See defaults)* | A list of listeners advertised to clients. Must **ONLY** include Broker listeners (e.g., `PLAINTEXT://...`). | | ||
| | `amq_streams_kraft_controller_listener_names` | `"CONTROLLER"` | The listener name used by the controller quorum (must match an entry in `listeners`). | | ||
| | `amq_streams_kraft_inter_broker_listener_name` | `"PLAINTEXT"` | The listener name used for replication between brokers. | | ||
| | `amq_streams_kraft_log_dirs` | `{{ amq_streams_kraft_data_dir }}` | The comma-separated list of directories for log data. Usually matches the data dir. | | ||
| | `amq_streams_kraft_log_retention_hours` | `168` | The number of hours to keep log segments before deletion (Default: 7 days). | | ||
| | `amq_streams_kraft_priv_escalation` | `yes` | Controls whether tasks (like creating directories and formatting storage) run with elevated privileges (`become: true`). | | ||
|
|
||
| ## Example Playbook | ||
|
|
||
| ```yaml | ||
| --- | ||
| - hosts: kafka_brokers | ||
| vars: | ||
| amq_streams_common_version: "3.7.0" | ||
| amq_streams_enable_kraft: true | ||
|
|
||
| roles: | ||
| # Install Java and Kafka Binaries | ||
| - role: amq_streams_common | ||
|
|
||
| # Configure and Format Storage for KRaft | ||
| - role: amq_streams_kraft | ||
| when: amq_streams_enable_kraft | bool | ||
|
|
||
| # Start the Kafka Service | ||
| - role: amq_streams_broker | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| Apache License v2.0 or later | ||
|
|
||
| ## Author Information | ||
|
|
||
| * [Ranabir Chakraborty](https://github.com/RanabirChakraborty) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| amq_streams_install_dir: "/opt" | ||
| amq_streams_kafka_home: "{{ amq_streams_install_dir }}/kafka_{{ amq_streams_common_version }}/" | ||
| amq_streams_kraft_config_dir: "{{ amq_streams_kafka_home }}/config" | ||
| amq_streams_kraft_data_dir: "{{ amq_streams_kafka_home }}/data/kraft" | ||
| amq_streams_cluster_id: "" | ||
| amq_streams_kraft_node_id: 1 | ||
| amq_streams_kraft_listener_port: 9092 | ||
| amq_streams_kraft_controller_port: 9093 | ||
| amq_streams_kraft_controller_quorum_voters: "1@{{ ansible_host }}:{{ amq_streams_kraft_controller_port }}" | ||
| amq_streams_kraft_listeners: | ||
| - "PLAINTEXT://0.0.0.0:{{ amq_streams_kraft_listener_port }}" | ||
| - "CONTROLLER://0.0.0.0:{{ amq_streams_kraft_controller_port }}" | ||
| amq_streams_kraft_advertised_listeners: | ||
| - "PLAINTEXT://{{ ansible_host }}:{{ amq_streams_kraft_listener_port }}" | ||
| amq_streams_kraft_controller_listener_names: "CONTROLLER" | ||
| amq_streams_kraft_inter_broker_listener_name: "PLAINTEXT" | ||
| amq_streams_kraft_process_roles: "broker,controller" | ||
| amq_streams_kraft_log_dirs: "{{ amq_streams_kraft_data_dir }}" | ||
| amq_streams_kraft_log_retention_hours: 168 | ||
| amq_streams_kraft_priv_escalation: yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| - name: Reload systemd | ||
| ansible.builtin.systemd: | ||
| daemon_reload: true | ||
|
|
||
| - name: Restart Kafka | ||
| ansible.builtin.systemd: | ||
| name: "{{ server_name | default('amq_streams_broker') }}" | ||
| state: restarted |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected.