Created
July 1, 2015 12:03
-
-
Save leonidlm/c2d14298d1a54a63881b to your computer and use it in GitHub Desktop.
ssh-core.sh
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
#!/bin/bash | |
ip_from_instance() { | |
echo $(aws ec2 describe-instances \ | |
--filters \ | |
"{\"Name\":\"tag:Name\", \"Values\":[\"$1\"]}" \ | |
"{\"Name\":\"instance-state-name\", \"Values\":[\"running\"]}" \ | |
--query='Reservations[0].Instances[0].PublicIpAddress' | tr -d '"') | |
} | |
ssh-core() { | |
local instance_name="$1" | |
# Determine if the instance is in staging or production | |
case "$instance_name" in | |
*staging*) | |
key="ansible-staging.pem" | |
;; | |
*production*) | |
key="ansible-production.pem" | |
;; | |
*) | |
echo "Unknown instance name '$instance_name'" | |
exit 1 | |
esac | |
ssh-add "/home/leonid/.ssh/$key" | |
ssh -A core@$(ip_from_instance "$instance_name") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment