Permalink
Browse files

Add new cookbook to set hostname to node name (disabled by default)

  • Loading branch information...
pauldowman committed Dec 16, 2011
1 parent 18aa95a commit e0cded7d57c468c7e5a8b59f6236b9409780fd0d
Showing with 27 additions and 2 deletions.
  1. +23 −0 cookbooks/chefonrails/recipes/hostname.rb
  2. +1 −0 cookbooks/chefonrails/templates/default/hosts.erb
  3. +3 −2 roles/base.rb
@@ -0,0 +1,23 @@
+#
+# This recipe sets the hostname to the node name, useful for when you choose to
+# set descriptive node names. It removes characters that are illegal in
+# hostnames.
+#
+
+template "/etc/hosts" do
+ source "hosts.erb"
+ owner "root"
+ group "root"
+ mode 0644
+ backup false
+end
+
+execute "Reset Hostname" do
+ command "hostname --file /etc/hostname"
+ action :nothing
+end
+
+file "/etc/hostname" do
+ content node.name.gsub(/[^-[:alnum:]]/, '') # node names can have some chars that aren't allowed in hostnames
+ notifies :run, resources(:execute => "Reset Hostname"), :immediately
+end
@@ -0,0 +1 @@
+127.0.0.1 localhost.localdomain localhost <%= node.name %>
View
@@ -13,9 +13,10 @@
"recipe[postfix]",
"recipe[logwatch]",
"recipe[fail2ban]",
+ "recipe[chefonrails]",
+ #"recipe[chefonrails::hostname]",
"recipe[mail_monitor]",
- "recipe[screen]",
- "recipe[chefonrails]"
+ "recipe[screen]"
)
default_attributes "ntp" => {

0 comments on commit e0cded7

Please sign in to comment.