Skip to content

Instantly share code, notes, and snippets.

@someara
Created November 12, 2010 03:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save someara/673693 to your computer and use it in GitHub Desktop.
Save someara/673693 to your computer and use it in GitHub Desktop.
chef hostname
bash -c '
echo <%= @config[:chef_node_name] %> > /tmp/chef_node_name
cat /tmp/chef_node_name | cut -d. -f1 > /tmp/proper_hostname
cat /tmp/chef_node_name | cut -d. -f2 | tr -d "\n" > /tmp/proper_dnsdomainname
echo -n "." >> /tmp/proper_dnsdomainname
cat /tmp/chef_node_name | cut -d. -f3 >> /tmp/proper_dnsdomainname
IPV4ADDR=`ip addr | grep eth0 | grep "inet " | cut -d " " -f 6 | cut -d \/ -f 1`
PROPERHOSTNAME=`cat /tmp/proper_hostname`
PROPERDNSDOMAINNAME=`cat /tmp/proper_dnsdomainname`
NETCONF="/etc/hostname"
echo "${PROPERHOSTNAME}" > ${NETCONF}
(
cat <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
${IPV4ADDR} ${PROPERHOSTNAME}.${PROPERDNSDOMAINNAME} ${PROPERHOSTNAME}
EOF
) > /tmp/hosts
sudo mv /tmp/hosts /etc/hosts
sudo hostname $PROPERHOSTNAME
(
echo "export PS1=\"\\\\H:\\\\w\\\\\\$ \"" >> /etc/profile
)
sudo apt-get -y install wget
(
echo "deb http://apt.opscode.com/ lucid main" | sudo tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/packages@opscode.com.gpg.key | sudo apt-key add -
sudo apt-get update
)
echo "chef chef/chef_server_url string <%= Chef::Config[:chef_server_url] %>" | debconf-set-selections
sudo apt-get install -y chef
(
cat <<'EOP'
<%= IO.read(Chef::Config[:validation_key]) %>
EOP
) > /tmp/validation.pem
awk NF /tmp/validation.pem > /etc/chef/validation.pem
rm /tmp/validation.pem
(
cat <<'EOP'
log_level :info
log_location STDOUT
chef_server_url "<%= Chef::Config[:chef_server_url] %>"
validation_client_name "<%= Chef::Config[:validation_client_name] %>"
<% if @config[:chef_node_name] == nil %>
# Using default node name"
<% else %>
node_name "<%= @config[:chef_node_name] %>"
<% end %>
EOP
) > /etc/chef/client.rb
(
cat <<'EOP'
<%= { "run_list" => @run_list }.to_json %>
EOP
) > /etc/chef/first-boot.json
/usr/bin/chef-client -j /etc/chef/first-boot.json
'
@millisami
Copy link

Before with just the default 'chef-full' distro, the /etc/hosts file over ec2 is:

root@ip-10-93-23-188:~# cat /etc/hosts
127.0.0.1 localhost

# 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

Then after using this distro, the /etc/hosts is:

root@new-empower-i-82c334f2:~# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.252.41.173 new-empower-i-82c334f2.new-empower-i-82c334f2.new-empower-i-82c334f2 new-empower-i-82c334f2

Which is invalid is some service, e.g. mysql errors out with too-long-hostname when creating the database.

Can u refactor it?

@someara
Copy link
Author

someara commented Jan 25, 2013

This gist was a hack from long ago.

Something like this is better -

https://github.com/someara/fqdn-cookbook

-s

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