-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Problem
start-redpanda.yml derives node_id using grep on the broker IP:
rpk cluster status {{ redpanda_rpk_opts }} | sed 's/*//g' | grep {{ hostvars[inventory_hostname].private_ip }} | awk '{ print $1;}'grep matches substrings, so an IP like 172.31.241.1 also matches 172.31.241.153, returning multiple IDs and breaking subsequent logic.
Reproduction
- Have two brokers with similar IP prefixes:
172.31.241.1172.31.241.153
- Run the task on the host
172.31.241.1. - The command outputs two IDs (e.g.,
6and11) instead of one.
Expected
Match the host column exactly and return a single broker ID for the current host.
Proposed fix
Use awk to match column 2 exactly and strip the * from the ID:
- name: Establish node id
ansible.builtin.shell:
cmd: >-
rpk cluster status {{ redpanda_rpk_opts }} |
awk '$2=={{ hostvars[inventory_hostname].private_ip | quote }} { gsub(/\*/,"",$1); print $1 }'
register: node_id_out
changed_when: falseAlternative (more robust, requires jq)
Parse JSON output instead of text columns:
rpk cluster status {{ redpanda_rpk_opts }} -o json \
| jq -r '.brokers[] | select(.host=={{ hostvars[inventory_hostname].private_ip | tojson }}) | .id'Impact
Prevents incorrect node_id detection in environments where broker IPs share prefixes, improving reliability of maintenance/decommission tasks that depend on node_id.
Reference
roles/redpanda_broker/tasks/start-redpanda.yml (around the node_id derivation)
Metadata
Metadata
Assignees
Labels
No labels