You need to use lazy at the top level of the attribute:
On Sep 28, 2014, at 4:15 AM, Greg Barker < "> > wrote:
> I've got an xml file that is generated during a chef run by a third party utility, and I want to retrieve a value from this xml file and use it in a template variable. How should I go about doing that?
>
> I was thinking maybe something like this, but it didn't work. other_thing ends up being a blank value:
>
> template "/some/file.xml" do
> source "source_file.xml.erb
> variables(
> :some_thing = node["some"]["thing"],
> :other_thing = lazy {
> require "rexml/document"
> REXML::XPath.first(REXML::Document.new(File.new("#{node[:some][:dir]}/config.xml")), '//id').text
> }
> )
> end
> require "rexml/document"
> template "/some/file.xml" do
> source "source_file.xml.erb
> variables(lazy do
> :some_thing => node["some"]["thing"],
> :other_thing => REXML::XPath.first(REXML::Document.new(File.new("#{node[:some][:dir]}/config.xml")), '//id').text
> end)
> end
Archive powered by MHonArc 2.6.16.