Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2011 12:39
Show Gist options
  • Save anonymous/1048781 to your computer and use it in GitHub Desktop.
Save anonymous/1048781 to your computer and use it in GitHub Desktop.
DATA BAG(we have data bags for 3 data centers):
{"id":"denver",
"hosts":[
{"host":"tick.clocks.com", "ip":"1.2.3.1", "aliases":["tick"], "comment":"NTP Host"},
{"host":"tock.clocks.com", "ip":"1.2.3.4", "aliases":["tock","ntp2.clocks.com"], "comment":"NTP Host"}
]
}
ntphosts = search("ntp", "id:#{node.location}")
### Manage the host entries first
ntphosts.each do |databagitem|
databagitem["hosts"].each do |host|
Chef::Log.debug("ntp::default: configuring ntp host #{host}")
hosts_entry host["host"] do
ip host["ip"]
aliases host["aliases"]
comment host["comment"]
end
end
end
service "ntpd" do
supports [ :restart, :status, :stop, :condrestart, :start ]
action [ :enable ]
end
template "/etc/ntp.conf" do
source "ntp.conf.erb"
owner "root"
group "root"
mode 0644
variables(:ntphosts => ntphosts )
notifies :restart, resources("service[ntpd]")
end
TEMPLATE:
<% @ntphosts.each do |databagitem| %>
<% databagitem["hosts"].each do |host| %>
server <%= host["host"] %>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment