I am in the process of experimenting with Chef and here's one of them
knife create cookbook host_file_update
Then create the recipe
recipes/default.rb
templates/default/hosts.erb
knife create cookbook host_file_update
Then create the recipe
recipes/default.rb
hosts = search(:node, "*:*")
template "/etc/hosts" do
source "hosts.erb"
owner "root"
group "root"
mode 0644
variables(
:hosts => hosts,
:hostname => node[:hostname],
:fqdn => node[:fqdn]
)
end
And then the template file hosts.erb referenced abovetemplates/default/hosts.erb
127.0.0.1 localhost <% @hosts.each do |node| %> <%= node['ipaddress'] %> <%= node['hostname'] %> <%= node['fqdn'] %> <% end %>
Pretty useful, if you want to populate this automatically as and when you add servers. One of the next things to try is see if we can make Chef pick the additional IPs (e.g service net in Rackspace cloud) and create separate entries for it