Chef registration wget

I have a chef recipe that looks something like this:

Chef::Log.info('step1') # do stuff Chef::Log.info('step2') bash "do_wget" do code <<-EOF wget somefile EOF end Chef::Log.info('step3') # do stuff 

wget takes some time but recording ends like

 step1 step2 step3 bash script runs #indicates that the bash script from step 2 is running 

Is there a way to prevent logging from step 3 to executing a bash script?

+7
source share
2 answers

You should get acquainted with the anatomy of a chef . It has 2 stages: compilation and execution.

No action is taken in the recipe resources at the compilation stage - each resource being evaluated is just taken and placed in the Resource Collection . However, only regular Ruby code outside of resources is evaluated.

At the execution stage, he actually evaluates the collection of resources . But by this time all your registration messages have already been printed.

If you need to run ruby ​​code (including Chef logging) at runtime, there is a special Ruby Block resource for it

 ruby_block "Add logging step3" do block do Chef::Log.info('step3') end action :create end 

Another way could be: actually start the resource at the compilation stage:

 bash "do_wget" do code "wget somefile" action :nothing end.run_action :run 

Action: nothing is set so as not to run this resource twice (once at each stage).

+8
source

Instead, you can use a log resource, which, as I understand it, works at run time, since you need

 log "step2" do :info end 

or simply

 log "step 3" 

http://docs.opscode.com/resource_log.html

+3
source

All Articles