Skip to content

Instantly share code, notes, and snippets.

@powdahound
Created September 13, 2011 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save powdahound/1214360 to your computer and use it in GitHub Desktop.
Save powdahound/1214360 to your computer and use it in GitHub Desktop.
hosts cookbook
# Find all other nodes
nodes = {}
search(:node, "chef_environment:#{node.chef_environment}") do |n|
# skip current node
if n[:fqdn] and n[:fqdn] != node[:fqdn]
nodes[n[:fqdn]] = n
end
end
Chef::Log.info "Other hosts: #{nodes.keys.sort.join(', ')}"
template "/etc/hosts" do
source "hosts.erb"
owner "root"
group "root"
mode 0644
variables(
:nodes => nodes
)
end
127.0.0.1 <%= @node[:fqdn] %> <%= @node[:hostname] %> localhost
# Network nodes
<% if @nodes -%>
<% @nodes.keys.sort.each do |fqdn| %>
<%= @nodes[fqdn][:ipaddress] %> <%= fqdn %> <%= @nodes[fqdn][:hostname] %>
<% end %>
<% end -%>
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment