Chef kitchen.local.yml属性移除后仍生效缓存问题求助
Let’s break down what’s happening here and walk through practical fixes to get your attributes behaving as expected:
Why This Happens
When you remove an overridden attribute from kitchen.local.yml, Test Kitchen might still cling to old values for two key reasons:
- Unclean test VMs: If you’re reusing existing VMs (via
kitchen convergeinstead of rebuilding from scratch), old attribute data can linger in the VM’s filesystem or Chef’s local cache. - Local Test Kitchen cache: The
.kitchendirectory in your project stores state, merged configurations, and temporary files from previous runs—this can hold onto old attribute values even after you edit your YAML files.
Step-by-Step Fixes
1. Fully Destroy and Rebuild Your Test VMs
Partial updates won’t clear out stale attribute data. Start fresh by wiping all existing test instances:
# Destroy all test VMs (the -a flag targets all platforms/nodes) kitchen destroy -a
Then rebuild the environment from scratch:
kitchen converge
This ensures the VM starts with no leftover files or cached Chef data.
2. Clear Test Kitchen’s Local Cache
The .kitchen directory is often the hidden culprit for "stuck" configurations. Delete it to force Test Kitchen to regenerate all configs from your latest files:
rm -rf .kitchen
After deletion, run kitchen converge again—this will pull in your updated kitchen.yml and default attributes from attributes/*.rb.
3. Verify Attribute Loading Priority
Double-check that no other config is overriding your default attributes. Chef’s attribute priority (from highest to lowest) is:
kitchen.local.yml>kitchen.yml- Environment attributes
- Role attributes
- Cookbook default attributes (
attributes/*.rb)
Ifkitchen.ymlitself has theFOOOattribute set, removing it fromkitchen.local.ymlwill still use thekitchen.ymlvalue, not the cookbook default. Make surekitchen.ymldoesn’t have a leftover entry forFOOO.
4. Clean Up Leftover Files in the VM
If you still see the FOOO value in /tmp on the VM, it’s likely a leftover from a previous Chef run. The kitchen destroy step should handle this, but if you manually kept the VM, you can clean it directly:
# SSH into the VM kitchen login # Delete Chef cache and tmp files linked to FOOO rm -rf /var/chef/cache /tmp/*FOOO* exit
Then run kitchen converge again to apply fresh configurations.
5. Debug with Verbose Logs
To track exactly where the FOOO attribute is coming from, run Test Kitchen with debug logging:
kitchen converge -l debug
Look for lines related to attribute loading—this will show you which file or config is setting the value, helping you catch any hidden overrides.
Final Check
After completing these steps, your test environment should respect the removal of the overridden attribute and fall back to the default values in attributes/*.rb.
内容的提问来源于stack exchange,提问作者Ondra Žižka

