Skip to content

Instantly share code, notes, and snippets.

@Jonty
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonty/cc138ed56a2522b4d89c to your computer and use it in GitHub Desktop.
Save Jonty/cc138ed56a2522b4d89c to your computer and use it in GitHub Desktop.
A bash alias to allow you to invoke vagrant commands on chef-kitchen created VM's.
function kitchenvagrant {
shopt -s nullglob
COMMAND=$1
VM=$2
BASEPATH=".kitchen/kitchen-vagrant/"
VPATH="."
if [ ! -e ".kitchen/kitchen-vagrant/" ]; then
echo "Can't find .kitchen - are you in the correct path?"
return
fi
if [ "$COMMAND" != '' ] && [ "$VM" != '' ]; then
VPATH="$BASEPATH$VM"
VMS=($VPATH*)
if [ ${#VMS[@]} -eq 1 ] && [ $VPATH != ${VMS[0]} ]; then
echo "Assuming you meant $(echo ${VMS[0]} | grep -o -E '[^/]+$') and continuing..."
VPATH=${VMS[0]}
fi
if [ ! -e $VPATH ]; then
echo "VM $VM* not found. VM's available:"
ls $BASEPATH
return
fi
fi
(cd $VPATH && vagrant $COMMAND)
}
alias kvagrant=kitchenvagrant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment