11. Resource
• 設定の最小単位
template '/etc/apache2/sites-available/www.example.jp' do
– ファイル source 'www.example.jp.erb'
mode '0644' ファイルを更新したら
action :create apache2サービスを
notifies :restart, "service[apache2]" 再起動
end
– パッケージ %w{zsh zip sysstat libcache-cache-perl}.each do |pkg|
package pkg do
action :install 完全にRuby
end
end
firewall_rule "zabbix" do
– ファイアウォール port 10050
source "192.0.2.5"
action :allow
notifies :enable, "firewall[ufw]"
end
12. Recipe
• 複数のResourceで構成されるひとまとまり
munin_servers = [' 192.0.2.6/32', ' 192.0.2.140 /32']
package "munin-node"
service_name = node['munin']['service_name'] Rubyの内部DSLなので
変数とかも利用し放題
service service_name do
supports :restart => true
action :enable
end サーバ毎の設定を利用
template "#{node['munin']['basedir']}/munin-node.conf" do
source "munin-node.conf.erb"
mode 0644
variables :munin_servers => munin_servers 変数をerbに渡す
notifies :restart, "service[#{service_name}]"
end
サーバの情報を利用して分岐
case node['platform']
when "arch", "smartos"
execute "munin-node-configure --shell | sh" do
not_if { Dir.entries(node['munin']['plugins']).length > 2 }
notifies :restart, "service[#{service_name}]"
end
end
13. Template
log_level 4
log_file /var/log/munin/munin-node.log
port 4949
pid_file /var/run/munin/munin-node.pid
background 1
setseid 1
# Which port to bind to;
host * サーバ毎の設定を利用
user root
group <%= node['munin']['root']['group'] %>
setsid yes
<% end %>
# A list of addresses that are allowed to connect. This must be a
# regular expression, due to brain damage in Net::Server, which
# doesn't understand CIDR-style network notation. You may repeat
# the allow line as many times as you'd like
引き渡された変数を利用
allow ^127¥.0¥.0¥.1$
<% @munin_servers.sort.each do |server| -%>
cidr_allow <%= server %>
<% end -%>