2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 02:52:07 +00:00

Keep known_hosts cleaner

When repeating osdeploy initialize
of local known_hosts, more
gracefeully avoid duplicate entries.
This commit is contained in:
Jarrod Johnson 2022-03-02 16:04:01 -05:00
parent 687136131e
commit 15e7e4464e

View File

@ -297,9 +297,29 @@ def initialize(cmdset):
if cmdset.l:
local_node_trust_setup()
if cmdset.k:
with open('/etc/ssh/ssh_known_hosts', 'a+b') as skh:
cas = set([])
cakeys = set([])
try:
with open('/etc/ssh/ssh_known_hosts', 'rb') as skh:
for line in skh.read().split(b'\n'):
try:
cakey = line.split()[3]
cakeys.add(cakey)
except IndexError:
pass
if line:
cas.add(line)
except IOError:
pass
with open('/etc/ssh/ssh_known_hosts', 'wb') as skh:
for ca in cas:
skh.write(ca)
skh.write(b'\n')
for cafile in glob.glob('/var/lib/confluent/public/site/ssh/*.ca'):
cacert = open(cafile, 'rb').read()
cakey = cacert.split()[1]
if cakey in cakeys:
continue
cacert = b'@cert-authority * ' + cacert
skh.write(cacert)
if cmdset.g: