chef client installation

by yann
58 deployments · 16 still active · last rev. 6 years ago

Let the pros handle this server setup.

This setup a chef-client ready to talk to your chef-server.

After booting your client you'll need to copy your server's /etc/chef/validation.pem at the same location in your client, and then re-run chef-client

Compatible with: No distros currently supported
						#!/bin/bash

# <udf name="privip" label="private ip to install to eth0:0">
# <udf name="hostname" label="hostname">
# <udf name="chef_server" label="chef server ip address">
# <udf name="ubuntu_mirror" label="ubuntu mirror url" default="http://us.archive.ubuntu.com/ubuntu">
source <ssinclude StackScriptID="476">

logfile=/root/stackscript.log
echo "Setting up host with chef" >> $logfile

echo "Adjusting sources.list (destructively)" >> $logfile

cat >/etc/apt/sources.list <<EOF
deb $UBUNTU_MIRROR lucid main restricted universe multiverse
deb-src $UBUNTU_MIRROR lucid main restricted universe multiverse

deb $UBUNTU_MIRROR lucid-updates main restricted universe multiverse
deb-src $UBUNTU_MIRROR lucid-updates main restricted universe multiverse

# 
# Security updates 
#
deb http://security.ubuntu.com/ubuntu lucid-security main restricted universe multiverse 
deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted universe multiverse 
EOF

apt-get update

## Adjusted from opscode wiki
echo "installing chef via ruby gems" >> $logfile
apt-get -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert
cd /tmp
wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
tar zxf rubygems-1.3.6.tgz
cd rubygems-1.3.6
ruby setup.rb
ln -sfv /usr/bin/gem1.8 /usr/bin/gem
gem sources -r http://gems.rubyforge.org/
gem sources -a http://rubygems.org/
gem install chef

echo "creating solo.rb" >> $logfile

cat > /root/solo.rb <<EOF
file_cache_path "/tmp/chef-solo"
cookbook_path "/tmp/chef-solo/cookbooks"
recipe_url "http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz"
EOF

echo "Creating chef.json" >> $logfile

cat > /root/chef.json <<EOF
{
  "bootstrap": {
    "chef": {
      "url_type": "http",
      "init_style": "runit",
      "path": "/srv/chef",
      "serve_path": "/srv/chef",
      "server_fqdn": "${CHEF_SERVER}"
    }
  },
  "run_list": [ "recipe[bootstrap::client]" ]
}
EOF

echo "Running chef-solo" >> $logfile

# broken see the issue: http://github.com/opscode/cookbooks/issues#issue/7
# seems to be fixed now
chef-solo -c /root/solo.rb -j /root/chef.json >> $logfile 2>&1
#chef-solo -c /root/solo.rb -j /root/chef.json >> $logfile 2>&1
#chef-solo -c /root/solo.rb -j /root/chef.json >> $logfile 2>&1

echo "Done" >> $logfile