Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EC2 の踏み台の .ssh/config 更新するクン
#!/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