[chef] Re: Helper and Resource Order


Chronological Thread 
  • From: Nathen Harvey < >
  • To: " " < >
  • Subject: [chef] Re: Helper and Resource Order
  • Date: Fri, 28 Aug 2015 16:36:52 -0400

Douglas,

chef-client uses a multi-stage process.  The first stage is known as the "compile" phase in which all ruby code is evaluated and a resource collection is built.  The second stage, known as the "execute" phase, performs the test-and-repair operations on each of the resources in the resource collection, in order.

Since `func()` is straight ruby, it will be executed during the compile phase.

If you'd like to log messages during the execute phase, please use a `log` resource (http://docs.chef.io/resource_log.html).

Check the docs (http://docs.chef.io/chef_client.html#the-chef-client-title-run) for a more detailed description of what happens and when during a chef-client run.

Thanks,
Nathen

On Fri, Aug 28, 2015 at 4:27 PM, Douglas Garstang < " target="_blank"> > wrote:
I have a default recipe with this:

file '/tmp/foo' do
end
::Chef::Recipe.send(:include, Helpers)
func()



and a helper function in libaries/ with this:

module Helpers
  def func()
    Chef::Log.info("I am here")
  end
end

My chef run in vagrant shows this:

==> node1: [2015-08-28T20:24:53+00:00] INFO: I am here
==> node1: [2015-08-28T20:24:53+00:00] INFO: file[/tmp/foo] created file /tmp/foo


Obviously, the helper function func() is being called and executed before the file resource, even though the order dictates the file resource should run first. How can I ensure a specific order?

Thanks,
Douglas





Archive powered by MHonArc 2.6.16.

§