Chef has different execution phases. Especially the compile and converge phase are important when writing cookbooks: the resources are collected in the compile phase and are executed in the converge phase.
In some special cases you might want to have dynamic resources, which are created and executed in the converge phase. The main background is that you want to react on something you known in the execution phase only.
Given a situation where you want to cleanup configuration files, which get installed by some package during a chef run (real examples might be apache on debian or freeradius on RHEL). You can try to solve this situation like this:
# Our module configuration
template '/etc/raddb/mods-available/eap-tls' do
Dir.glob('/etc/raddb/mods-available/*').each do |mod_path|
file_name = File.basename(mod_path)
next if file_name == 'eap-tls'
file mod_path do
However this will not work: you try to glob over
/etc/raddb/mods-available in the compile phase, but this path doesn’t exist as freeradius gets installed in the converge phase.
Read more →