- From: Noah Kantrowitz <
>
- To:
- Subject: [chef] Re: Chef and find a json file generated from a previous recipe
- Date: Tue, 2 Jun 2015 16:36:53 -0700
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
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail
Archive powered by MHonArc 2.6.16.