Created
May 12, 2014 13:19
-
-
Save jujhars13/864337424ca9f8a6fbfb to your computer and use it in GitHub Desktop.
opening up aws ec2 security groups
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
echo "Getting container/machine IP address..." | |
ip_address=`curl -s icanhazip.com` | |
if [ -z "$ip_address" ];then #if icanhasip failed | |
ip_address=`curl -s ifconfig.me` | |
if [ -z "$ip_address" ];then #if still can't get ipaddress | |
echo "Cannot get IP address, borked :-(" | |
exit 1 # terminate and indicate error | |
fi | |
else | |
echo "Got IP address of $ip_address" | |
fi | |
echo "Opening up SSH on security group:$ec2_security_group_id for $ip_address" | |
# see http://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html | |
aws --region=$aws_region ec2 authorize-security-group-ingress --group-id $ec2_security_group_id --protocol tcp --port 22 --cidr $ip_address/32 | |
echo "Running ansible git deploy playbook" | |
# my ansible/capistrano commands go here | |
echo "Removing $ip_address from security group:$ec2_security_group_id" | |
# see http://docs.aws.amazon.com/cli/latest/reference/ec2/revoke-security-group-ingress.html | |
aws --region=$aws_region ec2 revoke-security-group-ingress --group-id $ec2_security_group_id --protocol tcp --port 22 --cidr $ip_address/32 |
👍 still useful 3 later
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in conjunction with CircleCI.com to open up our ec2 security groups to enable ansible based deploy commands.