Chef local cookbook development

In the following recipe

lazy_message = 'Hello World'

file 'lazy_message' do
path '/tmp/lazy.txt'
content "#{lazy_message}"
end

execute 'yum-makecache' do
command 'yum makecache'
action :nothing
notifies :create, 'file[message]',:immediately
end

package 'bind-utils' do
action :install
notifies :run,'execute[yum-makecache]',:before
end

file 'message' do
path '/tmp/message'
content lazy{ "#{lazy_message}" }
end

lazy_message = 'Goodbye world'


I think 
lazy_message = 'Hello world' and
lazy_message ='Goodbye world'  is pure ruby code

so it must be evaluated at compile time and for execution phase, the value of lazy_message should be 'Goodbye world'. but that is not the same,
it seems that these both statements are evaluated during the execution phase. But in lecture, its mentioned that pure ruby will get evaluated during the compile phase.
  • post-author-pic
    Keith T
    01-08-2019

    Hi Akashdeep,


    It works exactly the way that you've described. I think the confusion here is that your "file[lazy_message]" resource isn't using lazy, but the "file[message]" resource is. You'll notice that `/tmp/message` will contain "Goodbye world", while `/tmp/lazy.txt` will contain "Hello world".

    Hopefully, that clears up what's going on.

Looking For Team Training?

Learn More