Created
June 27, 2011 12:39
-
-
Save anonymous/1048781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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