Created
September 19, 2017 21:00
-
-
Save blackknight36/b774e8c2936c4ad92f977707644f4819 to your computer and use it in GitHub Desktop.
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/python | |
import commands, os | |
def add_keys(host): | |
hostkeys = { | |
'rsa': { | |
'public_key': '', | |
'private_key': '' | |
}, | |
'ecdsa': { | |
'public_key': '', | |
'private_key': '' | |
}, | |
'ed25519': { | |
'public_key': '', | |
'private_key': '' | |
}, | |
} | |
data = open("/home/00/user0/projects/puppet/hieradata/nodes/example.com/%s.yaml" %host, "a") | |
data.write("\n") | |
data.write("openssh:\n") | |
data.write(" hostkeys:\n") | |
for x in ['rsa', 'ecdsa', 'ed25519']: | |
try: | |
p = open("ssh_host_%s_key.pub" %x) | |
except: | |
print "%s key not found" %x | |
continue | |
hostkeys[x]['private_key'] = commands.getoutput("eyaml encrypt -o block -f ssh_host_%s_key 2>/dev/null" %x) | |
data.write(" %s:\n" %x) | |
data.write(" private_key: >\n") | |
data.write(" %s\n" %hostkeys[x]['private_key']) | |
data.write(" public_key: |\n") | |
data.write(" %s\n" %p.read()) | |
os.chdir('/home/00/user0/projects/puppet/modules/files/files/private') | |
for host in os.listdir('.'): | |
key_dir = "/home/00/user0/projects/puppet/modules/files/files/private/%s/sshd" %host | |
try: | |
os.chdir(key_dir) | |
except: | |
print "No ssh keys for %s" %host | |
continue | |
add_keys(host) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment