Play failed 'nginx_running is undefined' on hosts where the `register` step was skipped. Root cause: A registered var was only set on hosts where the prior task ran. The fix: Guard with `is defined`/`default()`; register consistently.
A production war story from the TheCodeForge Ansible series — the incident, why it happened, and the exact fix.
⏳ Timestamps:
0:00 - Cold open: The conditional check 'nginx_running' failed. The error was: error while evaluating conditional (nginx_running): 'nginx_running' is undefined on some hosts.
0:11 - Intro
0:18 - What Are They?
0:33 - The When Clause
0:59 - Loop Keyword
1:17 - Legacy with_items
1:31 - Loop Control
1:50 - Until, Retries, Delay
2:10 - Nested Loops
2:32 - Dictionary Loops
2:49 - Combine Conditionals & Loops
3:05 - The conditional check 'nginx_running' failed. The error was: error while evaluating conditional (nginx_running): 'nginx_running' is undefined on some hosts.
3:28 - Undefined variable in when
3:41 - The Fix
3:59 - ⚠ Gotcha: Using bare variable in when clause
4:09 - ⚠ Gotcha: Looping over undefined variable
4:16 - ⚠ Gotcha: Forgetting loop_var with include_tasks
4:27 - Version Caveat: `loop` Requires Ansible 2.5+
5:01 - Production Caveat: `until` Without `ignore_errors`
5:32 - Debugging Guide
5:46 - Interview Questions
6:05 - FAQ
6:21 - Key Takeaways
6:34 - Next up
6:49 - Wrap-up
👉 Full article + code: https://thecodeforge.io/devops/ansibl...
⏭ Next up: Ansible Handlers and Notifications
#ansible #devops #automation