Consider the following code:
node["cloudwatch"]["alarms"].each do |metric,keys|
script_name = "/root/.cloudwatch/create_cloudwatch_alarm-#{metric}.sh"
template script_name do
source "cloudwatch/create_cloudwatch_EC2_alarm.sh.erb"
owner "root"
group "root"
mode "0655"
variables(
:metric => metric,
:description => keys["description"],
:statistic => keys["statistic"],
:comparison => keys["comparison"],
:threshold => keys["threshold"],
:evalperiods => keys["evalperiods"],
:period => keys["period"]
)
notifies :run, "bash[populate-create_alarms]", :immediately
end
bash "populate-create_alarms" do
user "root"
cwd "/root/.cloudwatch/"
code <<-EOH
echo #{script_name} >> ./create_alarms.sh
EOH
action :nothing
end
end
This runs fine, but in the log I get the following warnings several times:
WARN: Cloning resource attributes for bash[populate-create_alarms] from prior resource (CHEF-3694)
WARN: Previous bash[populate-create_alarms]: /var/chef-solo/cookbooks/soapp/recipes/cloudwatch.rb:220:in `block in from_file'
WARN: Current bash[populate-create_alarms]: /var/chef-solo/cookbooks/soapp/recipes/cloudwatch.rb:220:in `block in from_file'
I understand why I'm getting the warnings, but I don't know how to avoid them. Clearly "populate-create_alarms"
should not be inside the node["cloudwatch"]["alarms"].each
block, but I don't know how to pass #{script_name}
to "populate-create_alarms"
. Anyone show me the proper way to do this?
Best Answer
Make the
bash
resource name unique, by e.g. the following code: