Chef-Solo Run

by breakyboy
16 deployments · 0 still active · last rev. 2 years ago

Set up and execute a chef-solo run.

Compatible with: Ubuntu 14.04 LTS, Ubuntu 12.04 LTS
						#!/bin/bash
#
# Written by Andres Rojas <breakyboy@gmail.com>

# <UDF name="cookbooks_location" label="Cookbooks location" example="http://www.example.com/cookbooks.tgz" />
# <UDF name="run_type" label="Run:" oneof="Run List,Attributes JSON" />
# <UDF name="run_value" label="Run List or JSON location"/>


# Install curl if necessary
CURL=$(dpkg-query -W --showformat='${Status}\n' curl | grep "install ok installed")
if [ -z "$CURL" ]; then apt-get -y install curl; fi

# Download cookbooks
curl -LO $COOKBOOKS_LOCATION

case "$RUN_TYPE" in
  "Run List") RUN_TYPE="o" ;;
  "Attributes JSON") 
    RUN_TYPE="j"
    curl -LO $RUN_VALUE
    RUN_VALUE=`basename $RUN_VALUE`
    ;;
esac

# Uninstall curl if it wasn't installed previously
if [ -z "$CURL" ]; then
  apt-get -y remove curl
  apt-get -y autoremove
  apt-get clean
fi

# Install the latest chef-client from omnibus
source <ssinclude StackScriptID=8659>

# Run chef-solo
COOKBOOKS=`basename $COOKBOOKS_LOCATION`
chef-solo -r $COOKBOOKS -$RUN_TYPE $RUN_VALUE