Skip to content

Instantly share code, notes, and snippets.

@srinivasmohan
Last active October 3, 2015 18:27
Show Gist options
  • Save srinivasmohan/2503676 to your computer and use it in GitHub Desktop.
Save srinivasmohan/2503676 to your computer and use it in GitHub Desktop.
Chef recipe (snippets) to setup FQDN, hostname, IP etc properly
#Knife invocations supply FQDN as the node name at creation time and this becomes hostname( option -N)
execute "Configure Hostname" do
command "hostname --file /etc/hostname"
action :nothing
end
#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
@bscott
Copy link

bscott commented Feb 1, 2013

Where is the Configure Hostname resource defined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment