!/bin/bash
/usr/bin/knife node delete -y -c /root/.chef/knife.rb <%= node['fqdn']%>
/usr/bin/knife client delete -y -c /root/.chef/knife.rb <%= node['fqdn']%>
containeruuid=($(aws ecs --region list-container-instances
--cluster <%= default['recipe_name']['cluster']%> --output text|cut -d '/' -f2))
myinstance=$(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)
for myuuid in "${containeruuid[@]}"
do
ecsinstance=$(aws ecs describe-container-instances
--cluster <%= default['recipe_name']['cluster']%>
--container-instances $myuuid
--output text --query containerInstances[].ec2InstanceId|cut -d: -f2)
if [[ $ecsinstance = $myinstance ]]
then
aws ecs deregister-container-instance
--cluster <%= default['recipe_name']['cluster']%>
--container-instance ${containeruuid} --force
exit
else
echo "Instance does not match inside the ecs cluster"
fi
done
No comments:
Post a Comment