Skip to content

Instantly share code, notes, and snippets.

@joenoon
Created March 8, 2011 04:23
Show Gist options
  • Save joenoon/859845 to your computer and use it in GitHub Desktop.
Save joenoon/859845 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
ME=$0
SSH_USER=$1
HOST=$2
SSH_TO="$SSH_USER@$HOST"
PASSWORD="${PASSWORD:-chefchefchef}"
USE_SUDO="${USE_SUDO:-yes}"
if [ "$USE_SUDO" == "yes" ]; then
SUDOAGE="sudo"
else
USE_SUDO="no"
SUDOAGE=""
fi
usage() {
echo "Usage: $ME user host"
echo " Optional env vars: PASSWORD, USE_SUDO (anything other than 'yes' means no. yes by default)"
}
if [ -z "$SSH_TO" ]; then
usage
exit 1
fi
CHEF_CLIENT=$(echo $SSH_TO | md5)
echo "Chef server provisioning with:"
echo " Host: $SSH_TO"
echo " Chef Password: $PASSWORD"
echo " Use sudo: $USE_SUDO"
echo " Chef client: $CHEF_CLIENT"
echo "Beginning bootstap..."
ssh "$SSH_TO" "{
set -e
if [ ! -e /etc/chef_bootstap_complete ]; then
if [ ! -e /mnt/1024Mb.swap ]; then
$SUDOAGE dd if=/dev/zero of=/mnt/1024Mb.swap bs=1M count=1024
$SUDOAGE mkswap /mnt/1024Mb.swap
$SUDOAGE swapon /mnt/1024Mb.swap
echo '/mnt/1024Mb.swap none swap sw 0 0' | $SUDOAGE tee -a /etc/fstab
fi
echo 'chef-server-webui chef-server-webui/admin_password password chefchefchef' | $SUDOAGE debconf-set-selections
echo 'chef-solr chef-solr/amqp_password password chefchefchef' | $SUDOAGE debconf-set-selections
echo 'chef chef/chef_server_url string http://localhost:4000' | $SUDOAGE debconf-set-selections
echo 'deb http://apt.opscode.com/ lucid main' | $SUDOAGE tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/[email protected] | $SUDOAGE apt-key add -
$SUDOAGE apt-get clean
$SUDOAGE apt-get update
$SUDOAGE apt-get install -y chef chef-server
$SUDOAGE knife configure -i --defaults -s http://localhost:4000 -r ''
$SUDOAGE knife client create $CHEF_CLIENT -n -a -f /usr/local/src/$CHEF_CLIENT.pem
$SUDOAGE touch /etc/chef_bootstap_complete
fi
}"
echo "The following services are listening:"
ssh "$SSH_TO" "{
netstat -tln
}"
echo "Setting up knife locally..."
mkdir -p ~/.chef/$CHEF_CLIENT
scp $SSH_TO:/usr/local/src/$CHEF_CLIENT.pem ~/.chef/$CHEF_CLIENT/$CHEF_CLIENT.pem
touch ~/.chef/$CHEF_CLIENT/knife.rb
knife configure --defaults -s http://$HOST:4000 -u $CHEF_CLIENT -r "" -c ~/.chef/$CHEF_CLIENT/knife.rb -l debug -y
echo "All set."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment