Created
November 16, 2011 17:38
-
-
Save fearoffish/1370770 to your computer and use it in GitHub Desktop.
Take a chef node name and tag it as that on ec2
This file contains hidden or 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 | |
# Grabs the list of nodes from chef and adds a tag for | |
# node_name to the appropriate instance | |
CMDNAME=tag_instances | |
TMPFILE=/tmp/${CMDNAME}.out.$$ | |
ec2-describe-tags | grep node_name > $TMPFILE | |
retval=$? | |
[ $retval -ne 0 ] && echo "Error running 'ec2-describe-tags'" && cat $TMPFILE && exit $retval | |
for i in `knife node list -F j | grep "\"" | sed -e "s/\,//" -e "s/\"//g"`; do | |
grep -q $i $TMPFILE | |
if [ $? -eq 0 ]; then | |
instance_id=`knife node show -F j $i | grep instance_id | awk '{print $2}' | awk -F, '{print $1}' | sed -e "s/\"//g"` | |
grep $instance_id $TMPFILE | grep -q $i | |
retval=$? | |
if [ $retval -ne 0 ]; then | |
#echo "ec2addtag $instance_id -t node_name=$i" | |
ec2addtag $instance_id -t node_name=$i | |
retval=$? | |
[ $retval -ne 0 ] && echo "Error running 'ec2addtag'" && exit $retval | |
else | |
echo "$instance_id:$i already tagged" | |
fi | |
else | |
echo "Skipping $i - Not AWS" | |
fi | |
done | |
[ -e $TMPFILE ] && rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment