Last active
August 29, 2015 14:06
-
-
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.
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
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