Skip to content

Instantly share code, notes, and snippets.

@irfn
Last active July 31, 2017 10:56
Show Gist options
  • Save irfn/5b0c857cfd1d3615e215dc36ffeba722 to your computer and use it in GitHub Desktop.
Save irfn/5b0c857cfd1d3615e215dc36ffeba722 to your computer and use it in GitHub Desktop.
pull ec2 hosts to dnsmasq
#!/usr/bin/env bash
cd $CHEF_INFRA_HOME/infrastructure;knife search node -a ipaddress "name:*p-* and chef_environment:production" | sed -e ':a' -e 'N' -e '$!ba' -e "s/:\n ipaddress:/ /g" | sed -e '/^\s*$/d' | awk '{print $2" "$1}'> /usr/local/etc/chef_hosts
cat /usr/local/etc/chef_hosts | awk '{print "host "$2"\n hostname " $1 "\n user ubuntu\n port 22\n IdentityFile ~/.ssh/id_rsa\n"}' > /usr/local/etc/ssh_config/chef
#/etc/resolver/dev
nameserver 127.0.0.1
#/usr/local/etc/dnsmasq.conf
domain-needed
bogus-priv
no-resolv
no-poll
no-hosts
resolv-file=/usr/local/etc/resolv.dnsmasq
addn-hosts=/usr/local/etc/hosts
address=/.dev/127.0.0.1
server=84.200.69.80 # DNS.WATCH
server=8.8.8.8 # Google
server=8.26.56.26 # Comodo Secure DNS
#!/usr/bin/env bash
aws ec2 describe-instances --output text --query "Reservations[*].Instances[*].[PrivateIpAddress,Tags[0].[Value][0]][0]" | grep -v "None" > /usr/local/etc/hosts
cat /usr/local/etc/hosts | awk '{print "host "$2"\n hostname " $1 "\n user ubuntu\n port 22\n IdentityFile ~/.ssh/id_rsa\n"}' > /usr/local/etc/ssh_config⏎
#!/bin/sh
aws ec2 describe-instances --output text --query "Reservations[*].Instances[*].[PrivateIpAddress,Tags[0].[Value][0]][0]" | grep -v "None" > /usr/local/etc/hosts
cat /usr/local/etc/hosts | awk '{print "host "$2"\n hostname " $1 "\n user ubuntu\n port 22\n IdentityFile ~/.ssh/id_rsa\n"}' > /usr/local/etc/ssh_config
@irfn
Copy link
Author

irfn commented Dec 25, 2016

Finally include via ~/ssh/config directive Include /usr/local/etc/ssh_config

Include /usr/local/etc/ssh_config/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment