我无法根据 node.chef_environment 的结果在模板上设置变量。当前,当我运行厨房收敛时,厨师在重新启动 nrpe 服务时运行错误,因为 NRPE 抱怨 allowed_hosts 为空白。这是我第一次写食谱,所以请原谅我所做的任何丑陋的事情。
if node.chef_environment == "development" || node.chef_environment == "qa" || node.chef_environment == "vagrant"
node.default['allowed_hosts'] = "ipaddr"
elsif node.chef_environment == "staging" || node.chef_environment == "production"
node.default['allowed_hosts'] = "ipaddr2"
end
case
when platform_family?("debian")
package "nagios-nrpe-server"
package "nagios-plugins-basic"
when platform_family?("rhel")
package "nagios-nrpe"
package "nagios-plugins-nrpe"
package "net-snmp-utils"
else
Chef::Application.fatal! "[nagios-nrpe client] unsupported platform family: #{node[:platform_family]}"
end
template "/etc/nagios/nrpe.cfg" do
source "nrpe.cfg.erb"
owner "root"
group "root"
mode "0644"
variables(
:allowed_hosts => node.default['allowed_hosts']
)
end
bash "wget" do
code <<-EOH
cd /usr/lib/nagios/
wget --no-check-certificate remote_source
EOH
end
directory "/usr/lib/nagios/plugins" do
action :delete
recursive true
end
execute "untar plugins" do
cwd "/usr/lib/nagios/"
command "tar zxvf cc_sys_nrpe.tar.gz"
end
directory "/usr/lib/nagios/plugins" do
mode "777"
recursive true
end
file "/usr/lib/nagios/cc_sys_nrpe.tar.gz" do
action :delete
end
service "nagios-nrpe-server" do
supports :status => true, :restart => true, :reload => true
action :restart
end