for host in node['mycookbook']['hosts'] do
template "/path/to/conf.d/#{host}.cfg" do
source 'file.cfg.erb'
owner 'owner'
group 'group'
mode 0664
end
end
and in my template file its like this:
host_name <% #{host} %>
This doesn’t seem correct as I’m getting all sorts of errors with regards to that statement.
I’ve also tried using:
host_name <%= host %>
but that didn’t work.
Can I use/how do I use the host variable within the template itself?
for host in node['mycookbook']['hosts'] do
template "/path/to/conf.d/#{host}.cfg" do
source 'file.cfg.erb'
owner 'owner'
group 'group' variables({host: host})
mode 0664
end
end
and to use it in your template, prepend @ to the variable name:
myHash.each do |host, ip|
template “/path/to/conf.d/#{host}.cfg” do
source "file.cfg.erb"
owner 'owner’
group 'group’
mode 0664
variables(
host: host,
ip: ip
)
end
end