Skip to content

Instantly share code, notes, and snippets.

@eedgar
Forked from srinivasmohan/whatsmyname.rb
Created January 21, 2013 08:51
Show Gist options
  • Save eedgar/4584696 to your computer and use it in GitHub Desktop.
Save eedgar/4584696 to your computer and use it in GitHub Desktop.
#Knife invocations supply FQDN as the node name at creation time and this becomes hostname( option -N)
#Ensure the hostname of the system is set to knife provided node name
file "/etc/hostname" do
content node.name
notifies :run, resources(:execute => "Configure Hostname"), :immediately
end
#This sets up script which will run whenever eth0 comes up(after reboot) to update /etc/hosts
cookbook_file "/etc/network/if-up.d/update_hosts" do
source "update_hosts.sh"
owner "root"
group "root"
mode 0555
backup false
end
#Execute this script now (firsttime) to set /etc/hosts to have the newly provisioned nodes address/hostname line
bash "update_hosts" do
user "root"
group "root"
cwd "/tmp"
code <<-EOH
export IFACE=eth0
/etc/network/if-up.d/update_hosts
EOH
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment