bk-id-check.yaml

Overview

The bk-id-check.yaml file is an automation playbook designed to validate configuration integrity for a group of hosts identified as "block keepers" (BKs). Its primary function is to ensure that each block keeper host defines a unique and non-empty identifier, NODE_ID. This validation is critical in distributed systems or clusters where unique identifiers prevent ambiguity and conflicts during operations.

Two main validation steps are performed:

  1. Presence Check: Confirms that every block keeper has a NODE_ID defined and that it is not empty.

  2. Uniqueness Check: Ensures that all NODE_ID values across block keepers are unique.

If either check fails, the playbook will abort execution with a descriptive error message.


Playbook Tasks

The playbook consists of two sequential tasks executed against the inventory group block_keepers.

Task 1: Verify NODE_ID presence for each BK

Example usage snippet:

- name: Verify NODE_ID presence for each BK
  fail:
    msg: "Each block keeper must define a non-empty NODE_ID (number or string)"
  when: >
    (
      groups['block_keepers']
      | map('extract', hostvars, 'NODE_ID')
      | select('equalto', none)
      | list
      | length
    ) > 0
    or
    (
      groups['block_keepers']
      | map('extract', hostvars, 'NODE_ID')
      | map('string')
      | map('trim')
      | select('equalto', '')
      | list
      | length
    ) > 0

Task 2: Verify NODE_ID uniqueness for each BK

Example usage snippet:

- name: Verify NODE_ID uniqueness for each BK
  fail:
    msg: "Duplicate NODE_ID found. Each block keeper must have a unique NODE_ID"
  when: >
    (
      groups['block_keepers']
      | map('extract', hostvars, 'NODE_ID')
      | map('string')
      | map('trim')
      | unique
      | list
      | length
    )
    !=
    (groups['block_keepers'] | length)

Implementation Details


Interaction with Other System Components


Visual Diagram

flowchart TD
A[Start: block_keepers group]
A --> B[Extract NODE_IDs from hostvars]
B --> C{Check NODE_ID presence}
C -->|Any missing or empty| D[Fail: "Each block keeper must define a non-empty NODE_ID"]
C -->|All present| E{Check NODE_ID uniqueness}
E -->|Duplicates found| F[Fail: "Duplicate NODE_ID found"]
E -->|All unique| G[Validation Passed]

This file focuses exclusively on validating NODE_ID configuration for block keeper hosts, ensuring reliable identification within the system. For details on host grouping, variable management, and failure handling mechanisms, see the topics on Ansible Inventory Management and Error Handling in Automation.