Chef local cookbook development

In the following recipe

lazy_message = 'Hello World'

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

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

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

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

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

    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