Skip to content

ninja76/aws_elb_ssh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build SSH configs and run commands on all AWS ELB/ASG members!

The Problem

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!

Usage

Install:

  1. git clone https://github.com/ninja76/aws_elb_ssh.git
  2. cd aws_elb_ssh; bundle install (this will install all the dependencies)
  3. Copy config/config.aws.rb.sample to config/config.aws.rb and add your AWS Key info
  4. Optional - Usage of 'Name' tags. Not needed if using the prefix option

Basic:

ruby get_elb_nodes.rb -n ELB_GROUP_NAME

Advanced:

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"
}
]
}

SSH Config Output:

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

Run Command:

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"

Prefixing:

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....

About

Simple AWS Automation Tool in Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages