Skip to content

Instantly share code, notes, and snippets.

@alangarf
Created January 15, 2016 04:02
Show Gist options
  • Save alangarf/2dce63ca77af09a17c20 to your computer and use it in GitHub Desktop.
Save alangarf/2dce63ca77af09a17c20 to your computer and use it in GitHub Desktop.
Shell script to restart all the salt minions on instances in the same VPC and AZ as this master running the script
#!/bin/bash
eth0_mac=$(curl -s http://169.254.169.254/latest/meta-data/mac)
eth0_ip=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4/)
vpc_id=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$eth0_mac/vpc-id)
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/)
region=${az::-1}
instances=$(aws --region $region ec2 describe-instances --filters "Name=vpc-id,Values=$vpc_id" "Name=availability-zone,Values=$az" --query 'Reservations[*].Instances[*].PrivateIpAddress' --output=text)
for instance in $instances; do
if [ $instance != "$eth0_ip" ]; then
echo $instance
# unfunk minions of an old master
#ssh $instance "sudo rm -rf /etc/salt/pki/"
# restart the minion
ssh $instance "sudo service salt-minion restart"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment