wip
This commit is contained in:
parent
ef5661a99a
commit
c075e696fe
4 changed files with 78 additions and 1 deletions
39
bundles/hosts/items.py
Normal file
39
bundles/hosts/items.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
from ipaddress import ip_address
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
def sorted_hostnames(hostnames):
|
||||||
|
return sorted(
|
||||||
|
hostnames,
|
||||||
|
key=lambda e: (len(e.split('.')), e),
|
||||||
|
)
|
||||||
|
|
||||||
|
def sorted_hosts_for_ip_version(version):
|
||||||
|
return OrderedDict(
|
||||||
|
sorted(
|
||||||
|
[
|
||||||
|
(ip, sorted_hostnames(hostnames))
|
||||||
|
for ip, hostnames in node.metadata.get('hosts').items()
|
||||||
|
if ip_address(ip).version == version
|
||||||
|
],
|
||||||
|
key=lambda e: ip_address(e[0]),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
sorted_hosts = OrderedDict({
|
||||||
|
**sorted_hosts_for_ip_version(4),
|
||||||
|
**sorted_hosts_for_ip_version(6),
|
||||||
|
})
|
||||||
|
ip_width = len(max(sorted_hosts.keys(), key=len))
|
||||||
|
|
||||||
|
files['/etc/hosts'] = {
|
||||||
|
'content': '\n'.join(
|
||||||
|
' '.join([
|
||||||
|
ip.ljust(ip_width, ' '),
|
||||||
|
*hostnames
|
||||||
|
])
|
||||||
|
for ip, hostnames in sorted_hosts.items()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
28
bundles/hosts/metadata.py
Normal file
28
bundles/hosts/metadata.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
defaults = {
|
||||||
|
'hosts': {
|
||||||
|
'127.0.0.1': [
|
||||||
|
'localhost',
|
||||||
|
node.name,
|
||||||
|
],
|
||||||
|
'::1': [
|
||||||
|
'localhost',
|
||||||
|
'ip6-localhost',
|
||||||
|
'ip6-loopback',
|
||||||
|
],
|
||||||
|
'fe00::0': [
|
||||||
|
'ip6-localnet'
|
||||||
|
],
|
||||||
|
'ff00::0': [
|
||||||
|
'ip6-mcastprefix'
|
||||||
|
],
|
||||||
|
'ff02::1': [
|
||||||
|
'ip6-allnodes'
|
||||||
|
],
|
||||||
|
'ff02::2': [
|
||||||
|
'ip6-allrouters'
|
||||||
|
],
|
||||||
|
'ff02::3': [
|
||||||
|
'ip6-allhosts'
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
|
@ -7,5 +7,15 @@
|
||||||
'systemd',
|
'systemd',
|
||||||
'systemd-networkd',
|
'systemd-networkd',
|
||||||
'systemd-timers',
|
'systemd-timers',
|
||||||
|
'hosts',
|
||||||
],
|
],
|
||||||
|
'metadata': {
|
||||||
|
'hosts': {
|
||||||
|
'10.0.10.2': [
|
||||||
|
'resolver.name',
|
||||||
|
'first.resolver.name',
|
||||||
|
'second.resolver.name',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
'metadata': {
|
'metadata': {
|
||||||
'id': 'ea29bdf0-0b47-4bf4-8346-67d60c9dc4ae',
|
'id': 'ea29bdf0-0b47-4bf4-8346-67d60c9dc4ae',
|
||||||
'bind': {
|
'bind': {
|
||||||
'hostname': 'ns.sublimity.de',
|
'hostname': 'resolver.name',
|
||||||
'zones': {
|
'zones': {
|
||||||
'sublimity.de': [],
|
'sublimity.de': [],
|
||||||
'freibrief.net': [],
|
'freibrief.net': [],
|
||||||
|
|
Loading…
Reference in a new issue