Skip to content

Commit 7f20026

Browse files
committed
docs(overrides): add variable scope behavior warning
Document that vars overrides persist in play scope for all subsequent roles. Includes best practices for avoiding variable name collisions.
1 parent be49ac8 commit 7f20026

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

overrides/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ cp -r roles/git/files/* overrides/roles/git/files/
134134
- **This directory is gitignored** - your customizations stay local
135135
- **Pull upstream cleanly** - no merge conflicts with your overrides
136136

137+
## Variable Scope Behavior
138+
139+
**Important:** Variables loaded from `overrides/roles/{role}/vars/main.yml` persist for the entire playbook run.
140+
141+
This is standard Ansible behavior - `include_vars` loads into play scope. After a role runs, its override variables remain set for all subsequent roles.
142+
143+
### Best Practices
144+
145+
1. **Use role-prefixed variable names** - `git_user_email` not `user_email`
146+
2. **Check role defaults first** - `roles/{role}/defaults/main.yml` shows expected names
147+
3. **Avoid generic names** - `config`, `version`, `name` could collide with other roles
148+
4. **Override only what you need** - fewer variables = fewer collision chances
149+
150+
This behavior matches how `group_vars/` works in Ansible - it's not a bug, just something to be aware of.
151+
137152
## Debugging Overrides
138153

139154
### Verify Override Detection

0 commit comments

Comments
 (0)