Skip to content

Instantly share code, notes, and snippets.

@stefhen
Last active May 13, 2016 17:27
Show Gist options
  • Save stefhen/53f9607254046a2769e9f4439eeac9b8 to your computer and use it in GitHub Desktop.
Save stefhen/53f9607254046a2769e9f4439eeac9b8 to your computer and use it in GitHub Desktop.
#! /usr/bin/sudo /bin/bash
set -x
set -e
# https://github.com/berkshelf/berkshelf-api/issues/112
export LC_CTYPE=en_US.UTF-8
if [ ! -e /usr/bin/chef-client ]; then
curl -L https://www.opscode.com/chef/install.sh | sudo bash
fi
chef_dir="/home/rightscale/.chef"
rm -rf $chef_dir
mkdir -p $chef_dir/chef-install
chmod -R 0777 $chef_dir/chef-install
mkdir -p $chef_dir/cookbooks
chown -R 0777 $chef_dir/cookbooks
#install packages when on ubuntu
if which apt-get >/dev/null 2>&1; then
apt-get -y update
apt-get install -y build-essential git #ruby2.0 ruby2.0-dev
fi
#install packages for centos
if which yum >/dev/null 2>&1; then
yum groupinstall -y 'Development Tools'
yum install -y libxml2 libxml2-devel libxslt libxslt-devel git
fi
#install berkshelf
/opt/chef/embedded/bin/gem install berkshelf --no-ri --no-rdoc
#checkout the chef server cookbook and install dependent cookbooks using berkshelf
cd $chef_dir
branch=""
if [ -n "$COOKBOOK_VERSION" ];then
branch="--branch ${COOKBOOK_VERSION}"
fi
git clone $branch https://github.com/RightScale-Services-Cookbooks/chef-server-blueprint.git
cd chef-server-blueprint
/opt/chef/embedded/bin/berks vendor $chef_dir/cookbooks
cd $HOME
if [ -e $chef_dir/chef.json ]; then
rm -f $chef_dir/chef.json
fi
#convert input array to array for json in chef.json below
IFS=","
addons_array=`echo $CHEF_SERVER_ADDONS | awk -v RS='' -v OFS='","' 'NF { $1 = $1; print "\"" $0 "\"" }'`
IFS=""
chef_version=""
if [ -n "$CHEF_SERVER_VERSION" ];then
chef_version="\"version\":\"$CHEF_SERVER_VERSION\","
fi
cat <<EOF> $chef_dir/chef.json
{
"chef-server": {
"accept_license": true,
"api_fqdn": "$CHEF_SERVER_FQDN",
$chef_version
"addons": [$addons_array],
"configuration":{
"notification_email":"$CHEF_NOTIFICATON_EMAIL"
}
},
"rsc_postfix":{
"smtp_sasl_user_name":"$SMTP_SASL_USER_NAME",
"smtp_sasl_passwd":"$SMTP_SASL_PASSWORD",
"relayhost":"$SMTP_RELAYHOST"
},
"run_list": [
"recipe[chef-server-blueprint::default]",
"recipe[chef-server::addons]",
"recipe[rsc_postfix::default]"
]
}
EOF
cat <<EOF> $chef_dir/solo.rb
cookbook_path "$chef_dir/cookbooks"
EOF
#cp -f /tmp/environment /etc/environment
/sbin/mkhomedir_helper rightlink
chef-solo -l $LOG_LEVEL -L /var/log/chef.log -j $chef_dir/chef.json \
-c $chef_dir/solo.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment