Djo
December 5, 2011, 7:05pm
1
I have a template
template “/etc/djo.dat” dosource "djo.dat.erb"mode 0644owner "root"group "root"variables({:domain => node[:domain],:pete => “jimmy”})end
I want pete = to different fixed values based on node[:domain]what is the best way to do this?
Where is the pre-populated value mapping stored?
If it's in a databag, you can/should be able to do something like this:
knife data bag edit who_is pete
{ "id": "pete",
"foo_node": "jimmy",
"bar_node": "jammy",
"baz_node": "johnny"
}
and have the section of the template read like something along these lines:
variables ({
:domain => node[:domain],
:pete => data_bag_item("who_is", "pete")[node[:domain]]
})
I tend to make the data_bag_item call before the template and
establish a variable then de-reference that because it's easier to
print out/debug that, but it's not always necessary.
-Peter
On Mon, Dec 5, 2011 at 2:05 PM, djo@dave-n-georgi.com wrote:
I have a template
template "/etc/djo.dat" do
source "djo.dat.erb"
mode 0644
owner "root"
group "root"
variables({
:domain => node[:domain],
:pete => "jimmy"
})
end
I want pete = to different fixed values based on node[:domain]
what is the best way to do this?
:pete => node[:domain] == "foo.com " > "bar" : "baz"
or
pete = case node[:domain]
when "foo.com "
"foo"
when /bar.com$/
"bar_and_sub"
end
variables({..., :pete => pete})
Untested but approximately that. It helps if you realise that this is Just Ruby (helps me anyway. Also helps here if you know ruby, mind.)
-ash
On 5 Dec 2011, at 19:05, djo@dave-n-georgi.com djo@dave-n-georgi.com wrote:
I have a template
template "/etc/djo.dat" do
source "djo.dat.erb"
mode 0644
owner "root"
group "root"
variables({
:domain => node[:domain],
:pete => "jimmy"
})
end
I want pete = to different fixed values based on node[:domain]
what is the best way to do this?
On 5 Dec 2011, at 19:16, Ash Berlin wrote:
:pete => node[:domain] == "foo.com " > "bar" : "baz"
This was meant to be
:pete => node[:domain] == "foo.com " ? "bar" : "baz"
-ash