You have an autoscale group with instances that are always coming and going. Sometimes its nessecery to SSH into them for troubleshooting, deployment or other tasks. But it can be a hassle to keep track of what the current IP addresses are for each instance. This script does that for you and even builds the SSH configs for you!
- git clone https://github.com/ninja76/aws_elb_ssh.git
- cd aws_elb_ssh; bundle install (this will install all the dependencies)
- Copy config/config.aws.rb.sample to config/config.aws.rb and add your AWS Key info
- Optional - Usage of 'Name' tags. Not needed if using the prefix option
ruby get_elb_nodes.rb -n ELB_GROUP_NAME
ruby get_elb_nodes.rb -n ELB_GROUP_NAME -s -u SSH_USER -k SSH_KEY_FILE -p PREFIX
or
ruby get_elb_nodes.rb -c myconfig.json
-s Enable SSH Config Output
-u SSH User used with -s
-k SSH Keyfile used with -s
-p Prefix of Hostname used with -s
-c myconfig.json
-r Run Command across all nodes in a ELB group
NEW: config file. This option allows you to store all of your ELB or ASG group information in a file to quickly generate the config for all of your groups
example myconfig.json:
{
"groups" : [
{
"groupName": "webprod",
"username" : "ubuntu",
"sshKey" : "/root/.ssh/prodkey.pem",
"elbName" : "PROD01-WEB0-webELB-XXXXXXX"
},
{
"groupName": "dbprod",
"username" : "ubuntu",
"sshKey" : "/root/.ssh/prodkey.pem",
"elbName" : "PROD01-SE-DBE-XXXXXXX"
}
]
}
This will output to STDOUT SSH style config blocks for each instance found in the ELB group
ruby get_elb_nodes.rb -n ELB_GROUP_NAME -s -u SSH_USER -k SSH_KEY_FILE
This will output to STDOUT SSH style config blocks for all the nodes defined in all ELB groups in myconfig.json
ruby get_elb_nodes.rb -c myconfig.json
This is will run the command "df -h" across all nodes and return the output to stdout:
ruby get_elb_nodes.rb -c myconfig.json -r "df -h"
Lets say you have 5 web servers in an ELB group,
by specifing a prefix (-p web ) of web the following Hostnames will be generated:
EX.
ruby get_elb_nodes.rb -n ELB_GROUP_NAME -s -u ubuntu -k ~/.ssh/mykey.pem -p web
Hostname web1
Host 1.1.1.1
User ubuntu
IdentityFile "~/.ssh/mykey.pem"
Hostname web2
Host 1.1.1.2
User ubuntu
IdentityFile "~/.ssh/mykey.pem"
etc....