[chef] Re: Re: Chef and find a json file generated from a previous recipe


Chronological Thread 
  • From: David Montgomery < >
  • To:
  • Subject: [chef] Re: Re: Chef and find a json file generated from a previous recipe
  • Date: Fri, 5 Jun 2015 14:06:58 +0800

wow..I see now..I now have a better understanding.....thanks for help

On Wed, Jun 3, 2015 at 7:36 AM, Noah Kantrowitz < " target="_blank"> > wrote:

On Jun 2, 2015, at 4:33 PM, David Montgomery < "> > wrote:

> Thanks,
>
> But is there a solution?  I have to use my python to generate the json file.  I leave if File.exists?("#{Chef::Config[:file_cache_path]}/zookeeper_hosts") I get a chef error and fails and not very pretty to have to run chef twice. Is this the best chef can do?
>

Delay the file read until converge time:

template "/etc/zookeeper/conf/zoo.cfg" do
  path "/etc/zookeeper/conf/zoo.cfg"
  source "cloudera.zoo.cfg.erb"
  owner "root"
  group "root"
  mode "0644"
  variables lazy { { :zookeeper =>  File.read("#{Chef::Config[:file_cache_path]}/zookeeper_hosts") } }
  notifies :restart, resources(:service => "zookeeper-server")
end

The lazy {} helper puts off evaluating a resource property until the first time it is used, which in this case should be after the file is written. You could also do a similar thing using the node.run_state hash to avoid the time cost or writing/reading a file. Overall this kind of coupling should be avoided though, cookbooks should be self-contained.

--Noah





Archive powered by MHonArc 2.6.16.

§