crans_bcfg2/Python/etc/ssh/ssh_known_hosts
Valentin Samir 88a7ea3534 [ssh_known_hosts] Il faut ajouter des \n maintenant sinon on a tout sur une ligne
Je ne sais pas pourquoi le comportement à changer, je ne vois rien pour entraîner ça
dans les dernier commits sur ce fichier.
2014-02-19 19:39:41 +01:00

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 in key_machines:
key_machines[key]=set()
for host in machine['host']:
key_machines[key].add(host.value)
domains=host.value.split('.')
key_machines[key].add(domains[0])
key_machines[key].add('.'.join(domains[0:2]))
for alias in machine['hostAlias']:
key_machines[key].add(alias.value)
domains=alias.value.split('.')
key_machines[key].add(domains[0])
key_machines[key].add('.'.join(domains[0:2]))
for ip in machine['ipHostNumber']:
key_machines[key].add("%s" % ip)
if len(machine.get('dnsIpv6', []))<1 or machine['dnsIpv6'][0].value:
for ip in machine['ip6HostNumber']:
key_machines[key].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("\n".join(output))