Skip to content

Conversation

@vivekgsharma
Copy link
Collaborator

@vivekgsharma vivekgsharma commented Oct 16, 2025

Problem

Deployment was failing with AnsibleUndefinedVariable: 'node' is undefined errors on certain HP masternodes (e.g., hp-masternode-3, 4, 6) that don't have the node variable defined in their inventory.

Solution

Added node is defined checks in the dashmate template before accessing node properties:

  1. Core log debug (line 139): Check node before accessing dashd_debug
  2. Drive image selection (line 281): Check node before accessing drive_debug
  3. GroveDB Visualizer (lines 316-317): Check node before accessing drive_debug for visualizer config
  4. Tenderdash log level (line 435): Add fallback to default log level when node undefined
  5. Tenderdash node keys (lines 441-442): Add empty string fallbacks for node key id and private key

Testing

  • Deployment now succeeds on nodes both with and without node variable defined
  • Template renders correctly with appropriate defaults when node is undefined

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced configuration template with safety checks to gracefully handle undefined variables, ensuring proper fallback values are used instead of causing potential runtime errors.

@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2025

Walkthrough

Updates Jinja2 conditional expressions in a dashmate template to safely handle undefined node variables by adding defensive guards (node is defined and) before property access, preventing runtime errors across multiple configuration blocks.

Changes

Cohort / File(s) Summary
Defensive Node Checks
ansible/roles/dashmate/templates/dashmate.json.j2
Added safety guards with (node is defined and node.get(...)) checks to multiple conditional expressions including log.debug.enabled, drive.image, grovedbVisualizer.enabled/host, tenderdash.log.level, and node.id/node.key defaults, with fallback values when node is undefined

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

The changes follow a consistent pattern of adding defensive guards across a single template file with similar logic repeated for different properties.

Poem

🐰 With whiskers twitching and a hop so spry,
I guard the node when it's undefined, oh my!
Each condition checked with "is defined" in place,
No more runtime errors—just a safer space! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title succinctly captures the primary change of adding safety checks in the dashmate template before accessing node properties, accurately reflecting the updates made to prevent undefined variable errors. It is clear, specific, and directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vivek/dashmate_fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
ansible/roles/dashmate/templates/dashmate.json.j2 (2)

139-139: Core debug logic looks good; minor spacing nit.

The defensive guard correctly prevents undefined variable errors, and the OR logic allows both global and per-node debug settings.

Optional: Add a space before %} for consistency with the rest of the template:

-            "enabled": {% if dashd_debug == 1 or (node is defined and node.get('dashd_debug', 0) == 1)%}true{% else %}false{% endif %},
+            "enabled": {% if dashd_debug == 1 or (node is defined and node.get('dashd_debug', 0) == 1) %}true{% else %}false{% endif %},

435-435: Correct fallback logic for Tenderdash log level.

The defensive guard prevents undefined variable errors, and the fallback chain correctly prioritizes node-specific settings over the global default.

Optional: The logic is slightly redundant since node.get('tenderdash_debug', tenderdash_log_level) already provides the fallback. However, this is not incorrect and the current form is explicit and clear.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed9c40b and ca6dded.

📒 Files selected for processing (1)
  • ansible/roles/dashmate/templates/dashmate.json.j2 (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: dashpay/dash-network-deploy#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-06T08:09:00.292Z
Learning: Applies to ansible/roles/dashmate/tasks/*.yml : Use `is defined` checks and conditional execution for variables such as `dashmate_group_check`, `dashmate_user_check`, `dash_conf_stat`, `dash_conf_changed`, `logrotate_config_stat`, `dashmate_update`, `dashmate_start_all`, `dashmate_restart_all`, `dashmate_install_result`, and `template_result` in Ansible tasks to prevent undefined variable errors
📚 Learning: 2025-08-06T08:09:00.292Z
Learnt from: CR
PR: dashpay/dash-network-deploy#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-06T08:09:00.292Z
Learning: Applies to ansible/roles/dashmate/tasks/*.yml : Use `is defined` checks and conditional execution for variables such as `dashmate_group_check`, `dashmate_user_check`, `dash_conf_stat`, `dash_conf_changed`, `logrotate_config_stat`, `dashmate_update`, `dashmate_start_all`, `dashmate_restart_all`, `dashmate_install_result`, and `template_result` in Ansible tasks to prevent undefined variable errors

Applied to files:

  • ansible/roles/dashmate/templates/dashmate.json.j2
🔇 Additional comments (2)
ansible/roles/dashmate/templates/dashmate.json.j2 (2)

281-281: LGTM! Drive debug configuration is correctly guarded.

The conditional logic consistently applies the node is defined guard before checking drive_debug, preventing undefined variable errors while enabling debug features when requested.

Also applies to: 316-317


441-442: Ignore fallback for node keys in dashmate.json.j2
The empty-string fallback for node.node_key.id and node.node_key.private_key is intentional for non-validator nodes and deployment tests show no errors.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@ktechmidas ktechmidas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vivekgsharma vivekgsharma merged commit 1ab69db into v1.0-dev Oct 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants