Skip to content

Commit c6ec684

Browse files
Merge pull request gianlucaborello#17 from speedenator/master
Added new keydir arg, python shebang, and generated comment
2 parents 4b39410 + 44ceb17 commit c6ec684

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

aws-ssh-config.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#!/usr/bin/env python
2+
13
import argparse
24
import re
35
import sys
46
import boto.ec2
7+
import time
58

69

710
AMIS_TO_USER = {
@@ -55,6 +58,7 @@ def main():
5558
parser.add_argument('--user', help='override the ssh username for all hosts')
5659
parser.add_argument('--default-user', help='default ssh username to use if we cannot detect from AMI name')
5760
parser.add_argument('--prefix', default='', help='specify a prefix to prepend to all host names')
61+
parser.add_argument('--keydir', default='~/.ssh/', help='location of private keys')
5862

5963
args = parser.parse_args()
6064

@@ -63,6 +67,11 @@ def main():
6367
counts_incremental = {}
6468
amis = {}
6569

70+
print "# Generated on " + time.asctime(time.localtime(time.time()))
71+
print "# " + " ".join(sys.argv)
72+
print "# "
73+
print
74+
6675
for region in boto.ec2.regions():
6776
if region.name in BLACKLISTED_REGIONS:
6877
continue
@@ -132,7 +141,10 @@ def main():
132141
counts_incremental[id] += 1
133142
id += '-' + str(counts_incremental[id])
134143

135-
print 'Host ' + args.prefix + id
144+
hostid = args.prefix + id
145+
hostid = hostid.replace(' ', '_') # get rid of spaces
146+
147+
print 'Host ' + hostid
136148
print ' HostName ' + ip
137149

138150
try:
@@ -141,7 +153,12 @@ def main():
141153
except:
142154
pass
143155

144-
print ' IdentityFile ~/.ssh/' + instance.key_name + '.pem'
156+
if args.keydir:
157+
keydir = args.keydir
158+
else:
159+
keydir = '~/.ssh/'
160+
161+
print ' IdentityFile ' + keydir + instance.key_name + '.pem'
145162
print ' StrictHostKeyChecking no' # just for me, removing this is usually a good choice
146163
print
147164

0 commit comments

Comments
 (0)