
recipes
으로 개발하는 방법을 배우기 시작했습니다 chef
. Ganglia Monitor
일부 서버(또는 nodes
Ganglia 문헌) 에 설치해야 합니다 . 그래서 나는 플랫폼이 이고 다른 많은 사람들이 올바른 패키지를 설치하는지 확인하고 ubuntu
있습니다 centOS
.
문제는 두 개의 서로 다른 파일이 있다는 것입니다 . 실제로 이 파일에는 서로 다른 .config
매개변수가 한두 개만 있습니다 . 파일을 올바르게 복사할 수 있도록 해당 파일이 속하는 .config
것을 감지하는 방법에 대한 도움이 필요합니다 . 지금까지 아래 스크립트를 개발할 수 있었지만 코드의 주석에 몇 가지 dobut가 있습니다.datacenter
server
.config
#
# Cookbook Name:: ganglia
# Recipe:: default
#
# Copyright 2013, Valter Henrique.com
#
# All rights reserved - Do Not Redistribute
#
# Installing Ganglia Monitor
case node[:platform]
when "ubuntu", "debian"
package "ganglia-monitor"
when "redhat", "centos", "fedora"
package "ganglia-gmond"
end
user "ganglia"
end
# Setting different .config files
case ipaddress
# DataCenter #1
# how put more options in the when condition ? A when for /^200.222./ or /^200.223./ ?
when /^200.222./
# putting config file
cookbook_file "/etc/ganglia/gmond.conf" do
owner "root"
group "root"
mode "0644"
source "dc1/gmond.conf"
notifies(:restart, "service[gmond]")
end
#DataCenter #2
when /^216.235./
cookbook_file "/etc/ganglia/gmond.conf" do
owner "root"
group "root"
mode "0644"
source "dc2/gmond.conf"
notifies(:restart, "service[gmond]")
end
end
이 코드를 더 나은 방법으로 개발하는 방법에 대한 제안이 있으십니까?
답변1
코드 중복을 피하기 위해 리소스 source
속성 에 변수를 사용할 수 있습니다 .cookbook_file
dc = case ipaddress
when /^200\.222\./
'dc1'
when /^216\.235\./
'dc2'
end
cookbook_file "/etc/ganglia/gmond.conf" do
owner "root"
group "root"
mode "0644"
source "#{dc}/gmond.conf"
notifies(:restart, "service[gmond]")
end