Created
April 29, 2012 03:22
-
-
Save cbsmith/2529255 to your computer and use it in GitHub Desktop.
Instant CentOS Minion on Joyent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Setups up a new CentOS machine on Joyent running a Salt minion talking to your salt master. From there, you can do the rest of your setup work from the Salt Master. | |
# Requires Joyent Command Line SDK be installed as well as Node's jsontool (npm install jsontool) | |
# If you don't provide a Joyent ID, the code assumes the master is labeled with metadata "salt-role=master" or with "role=salt-master" | |
# Tweak these variables should have done anything creative with your salt setup | |
SALT_ROOT=/ | |
SALT_MASTER_UID=root | |
#if you wrapped your salt-master deployment in a virtualenv, place its name here | |
VIRTUAL_ENV= | |
if [ -z "$2" ] | |
then | |
echo "Usage: `basename $0` machine_name package [salt-master-id]" | |
exit -1 | |
fi | |
MACHINE_NAME=$1 | |
PACKAGE=$2 | |
MASTER_ID=$3 | |
if [ -z "$MASTER_ID" ] | |
then | |
MASTER_IPS=`sdc-listmachines | json -c 'metadata.role=="salt-master"||metadata.salt-role=="master"' -a ips` | |
else | |
MASTER_IPS=`sdc-getmachine $MASTER_ID | json ips` | |
fi | |
MASTER_PRIVATE_IP=`json [0]<<<$MASTER_IPS` | |
MASTER_PUBLIC_IP=`json [1]<<<$MASTER_IPS` | |
MACHINE_ID=`sdc-createmachine -name $MACHINE_NAME --package "$PACKAGE" --dataset 'sdc:sdc:centos-6:1.0.1' --tag salt-role=minion --metadata salt-master=$MASTER_PRIVATE_IP --metadata user-script='yum -y install http://mirror.us.leaseweb.net/epel/6/i386/epel-release-6-5.noarch.rpm salt-minion && yum -y install salt-minion && echo "\`/lib/smartdc/mdata-get salt-master\` salt" >> /etc/hosts && service salt-minion start' | json id` | |
while [ `sdc-getmachine $MACHINE_ID | json state` != 'running' ]; do sleep 1; done | |
CMD="while [ ! -f $SALT_ROOT/etc/salt/pki/minions_pre/$MACHINE_ID ]; do sleep 1; done; salt-key -a $MACHINE_ID" | |
if [ -n "$VIRTUAL_ENV" ] | |
then | |
CMD="source $VIRTUAL_ENV/bin/activate && $CMD" | |
fi | |
echo "$CMD" | |
ssh -l root $MASTER_PUBLIC_IP su - $SALT_MASTER_UID "\"$CMD\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment