crans_bcfg2/Python/etc/ssh/ssh_known_hosts

41 lines
1.2 KiB
Python

# -*- coding: utf-8; mode: python -*-
include("mode/space")
include("ldap_conn")
header("Configuration du serveur ssh")
machines=ldap_conn.search("objectClass=machineCrans")
key_machines={}
for machine in machines:
for key in machine['sshFingerprint']:
if not key.value in key_machines.keys():
key_machines[key.value]=set()
for host in machine['host']:
key_machines[key.value].add(host.value)
domains=host.value.split('.')
key_machines[key.value].add(domains[0])
key_machines[key.value].add('.'.join(domains[0:2]))
for alias in machine['hostAlias']:
key_machines[key.value].add(alias.value)
domains=alias.value.split('.')
key_machines[key.value].add(domains[0])
key_machines[key.value].add('.'.join(domains[0:2]))
for ip in machine['ipHostNumber']:
key_machines[key.value].add("%s" % ip)
if len(machine.get('dnsIpv6', []))<1 or machine['dnsIpv6'][0].value:
for ip in machine['ip6HostNumber']:
key_machines[key.value].add("%s" % ip)
# On trie pour avoir des diff valident en appliquant bcfg2 sur les machines
output=[]
for key in key_machines.keys():
hosts=list(key_machines[key])
hosts.sort()
output.append("%s %s" % (','.join(hosts),key))
output.sort()
sys.stdout.write("".join(output))