Skip to content

Instantly share code, notes, and snippets.

@jujhars13
Created May 12, 2014 13:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jujhars13/864337424ca9f8a6fbfb to your computer and use it in GitHub Desktop.
Save jujhars13/864337424ca9f8a6fbfb to your computer and use it in GitHub Desktop.
opening up aws ec2 security groups
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
@jujhars13
Copy link
Author

Used in conjunction with CircleCI.com to open up our ec2 security groups to enable ansible based deploy commands.

@ObjectiveTruth
Copy link

👍 still useful 3 later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment