Last active
April 23, 2020 11:23
-
-
Save rummelonp/37d927df399e0000180ff7a264efd3b0 to your computer and use it in GitHub Desktop.
EC2 の踏み台の .ssh/config 更新するクン
This file contains hidden or 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
#!/usr/bin/env bash | |
aws --region=ap-northeast-1 ec2 describe-instances \ | |
--query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,Instance:InstanceId,Ip:PrivateIpAddress}' \ | |
| jq '.[] | .[]' \ | |
| jq --raw-output --slurp 'sort_by(.Name) | .[] | select(.Ip != null) | "Host " + .Name + "-" + .Instance, " HostName " + .Ip, ""' \ | |
> /home/ec2-user/.ssh/config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment