From 876be1edaf9758bf35ec8b1f73fb32aa4ceaaa21 Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Mon, 27 Sep 2021 13:28:26 +0200 Subject: space_server: vars: use dictionary for local_hosts This allows us to look up info on specific hosts without searching through the whole list. --- roles/space_server/templates/avahi-hosts.j2 | 16 +- roles/space_server/templates/dhcpd.conf.j2 | 18 +-- roles/space_server/templates/ipv4.rev.zone.j2 | 8 +- roles/space_server/templates/s.zone.j2 | 16 +- roles/space_server/vars/main.yml | 214 +++++++++++++------------- 5 files changed, 136 insertions(+), 136 deletions(-) (limited to 'roles/space_server') diff --git a/roles/space_server/templates/avahi-hosts.j2 b/roles/space_server/templates/avahi-hosts.j2 index 1e371e6..e64265a 100644 --- a/roles/space_server/templates/avahi-hosts.j2 +++ b/roles/space_server/templates/avahi-hosts.j2 @@ -1,16 +1,16 @@ -{% for host in local_hosts %} -{% if 'mdns' not in host or host.mdns %} -{% if 'ipv4' in host %} -{% for ip in host.ipv4 %} +{% for name, info in local_hosts.items() %} +{% if 'mdns' not in info or info.mdns %} +{% if 'ipv4' in info %} +{% for ip in info.ipv4 %} {% if loop.index <= 1 %} -{{ ip }} {{ host.name }}.local +{{ ip }} {{ name }}.local {% endif %} {% endfor %} {% endif %} -{% if 'ipv6' in host %} -{% for ip in host.ipv6 %} +{% if 'ipv6' in info %} +{% for ip in info.ipv6 %} {% if loop.index <= 1 %} -{{ ip }} {{ host.name }}.local +{{ ip }} {{ name }}.local {% endif %} {% endfor %} {% endif %} diff --git a/roles/space_server/templates/dhcpd.conf.j2 b/roles/space_server/templates/dhcpd.conf.j2 index a2d82a7..13fc3ab 100644 --- a/roles/space_server/templates/dhcpd.conf.j2 +++ b/roles/space_server/templates/dhcpd.conf.j2 @@ -158,17 +158,17 @@ subnet 10.42.3.0 netmask 255.255.255.0 { group { use-host-decl-names on; ddns-updates off; -{% for host in local_hosts %} -{% if 'mac' in host and 'ipv4' in host %} +{% for name, info in local_hosts.items() %} +{% if 'mac' in info and 'ipv4' in info %} -{% if 'description' in host %} - # {{ host.description }} +{% if 'description' in info %} + # {{ info.description }} {% endif %} - host {{ host.name }} { - hardware ethernet {{ host.mac }}; - fixed-address {{ host.ipv4|join(', ') }}; -{% if 'filename' in host %} - filename "{{ host.filename }}"; + host {{ name }} { + hardware ethernet {{ info.mac }}; + fixed-address {{ info.ipv4|join(', ') }}; +{% if 'filename' in info %} + filename "{{ info.filename }}"; {% endif %} } {% endif %} diff --git a/roles/space_server/templates/ipv4.rev.zone.j2 b/roles/space_server/templates/ipv4.rev.zone.j2 index 1736333..0c165de 100644 --- a/roles/space_server/templates/ipv4.rev.zone.j2 +++ b/roles/space_server/templates/ipv4.rev.zone.j2 @@ -1,11 +1,11 @@ 42.10.in-addr.arpa. 600 IN SOA space.labitat.dk. esmil.labitat.dk. 2019040101 7200 3600 604800 86400 42.10.in-addr.arpa. 600 IN NS space.labitat.dk. -{% for host in local_hosts %} -{% if 'ipv4' in host %} -{% for ip in host.ipv4 %} +{% for name, info in local_hosts.items() %} +{% if 'ipv4' in info %} +{% for ip in info.ipv4 %} {% if ip.startswith('10.42.') %} -{{ ip.split('.')[3] }}.{{ ip.split('.')[2] }}.42.10.in-addr.arpa. 600 IN PTR {{ host.name }}.s. +{{ ip.split('.')[3] }}.{{ ip.split('.')[2] }}.42.10.in-addr.arpa. 600 IN PTR {{ name }}.s. {% endif %} {% endfor %} {% endif %} diff --git a/roles/space_server/templates/s.zone.j2 b/roles/space_server/templates/s.zone.j2 index a392f3d..0394e98 100644 --- a/roles/space_server/templates/s.zone.j2 +++ b/roles/space_server/templates/s.zone.j2 @@ -8,17 +8,17 @@ labitrack.s. 600 IN A 185.38.175.70 labitrack.s. 600 IN AAAA 2a01:4262:1ab::cafe track.s. 600 IN A 185.38.175.70 track.s. 600 IN AAAA 2a01:4262:1ab::cafe -{% for host in local_hosts %} -{% if 'ipv4' in host or 'ipv6' in host %} +{% for name, info in local_hosts.items() %} +{% if 'ipv4' in info or 'ipv6' in info %} -{% if 'ipv4' in host %} -{% for ip in host.ipv4 %} -{{ host.name }}.s. 600 IN A {{ ip }} +{% if 'ipv4' in info %} +{% for ip in info.ipv4 %} +{{ name }}.s. 600 IN A {{ ip }} {% endfor %} {% endif %} -{% if 'ipv6' in host %} -{% for ip in host.ipv6 %} -{{ host.name }}.s. 600 IN AAAA {{ ip }} +{% if 'ipv6' in info %} +{% for ip in info.ipv6 %} +{{ name }}.s. 600 IN AAAA {{ ip }} {% endfor %} {% endif %} {% endif %} diff --git a/roles/space_server/vars/main.yml b/roles/space_server/vars/main.yml index 3da44f8..93fca5f 100644 --- a/roles/space_server/vars/main.yml +++ b/roles/space_server/vars/main.yml @@ -71,112 +71,112 @@ root: options: 'noatime,ssd,compress=lzo' local_hosts: -- name: space - description: Main router/infrastructure server - mdns: false - ipv4: - - 185.38.175.0 - ipv6: - - '2a01:4262:1ab::' -- name: doorputer - description: Front door controlling Raspberry Pi - mac: b8:27:eb:d9:92:00 - mdns: false - ipv4: - - 10.42.0.3 -- name: foodputer - mac: 00:21:86:ff:fa:cc - mdns: false - ipv4: - - 10.42.0.4 -- name: ap1 - mdns: false - ipv4: - - 10.42.0.5 -- name: ap2 - mdns: false - ipv4: - - 10.42.0.6 -- name: bunkerap1 - description: Wifi accesspoint in bunkers - mdns: false - ipv4: - - 10.42.0.7 -- name: switch - description: Space switch - mdns: false - ipv4: - - 10.42.0.9 -- name: voip - description: LinksysPAP2 SIP box for the phone - mac: 00:21:29:0c:91:65 - mdns: false - ipv4: - - 10.42.0.10 -- name: bunkerswitch - description: Switch in the bunkers - mdns: false - ipv4: - - 10.42.0.11 -- name: lathe - mdns: false - ipv4: - - 10.42.0.12 -- name: infraswitch - description: Switch for mediaconverting our 10G - mdns: false - ipv4: - - 10.42.0.13 -- name: anna - mac: 00:e0:c5:6e:d6:8d - ipv4: - - 10.42.1.9 -- name: piscreen2 - description: PixelFlut Raspberry Pi - mac: b8:27:eb:9b:64:d9 - ipv4: - - 10.42.1.12 -- name: pixelfluthafnium - description: PixelFlut Odroid - mac: 00:1e:06:45:38:08 - ipv4: - - 10.42.1.13 - ipv6: - - 2a01:4262:1ab:b:f100::000d -- name: printbrother - mac: 00:80:77:06:9f:26 - ipv4: - - 10.42.1.32 -- name: xeroxwax - mac: 00:00:aa:a7:ef:8b - mdns: false - ipv4: - - 10.42.1.33 -- name: infotron - description: Infoscreen Raspberry Pi - mac: b8:27:eb:2c:5d:3a - ipv4: - - 10.42.1.34 -- name: spacemon - mac: b8:27:eb:24:f8:50 - ipv4: - - 10.42.1.35 -- name: jumbotron - description: Jumbotron Raspberry Pi - mac: b8:27:eb:d3:c1:62 - ipv4: - - 10.42.1.36 -- name: hplaserjet - mac: 94:57:a5:ce:e2:6c - mdns: false - ipv4: - - 10.42.1.37 - ipv6: - - 2a01:4262:1ab:b:9657:a5ff:fece:e26c -- name: snakeskin - description: Snakeskin controlling Raspberry Pi - mac: b8:27:eb:9b:64:d9 - ipv4: - - 10.42.1.38 + space: + description: Main router/infrastructure server + mdns: false + ipv4: + - 185.38.175.0 + ipv6: + - '2a01:4262:1ab::' + doorputer: + description: Front door controlling Raspberry Pi + mac: b8:27:eb:d9:92:00 + mdns: false + ipv4: + - 10.42.0.3 + foodputer: + mac: 00:21:86:ff:fa:cc + mdns: false + ipv4: + - 10.42.0.4 + ap1: + mdns: false + ipv4: + - 10.42.0.5 + ap2: + mdns: false + ipv4: + - 10.42.0.6 + bunkerap1: + description: Wifi accesspoint in bunkers + mdns: false + ipv4: + - 10.42.0.7 + switch: + description: Space switch + mdns: false + ipv4: + - 10.42.0.9 + voip: + description: LinksysPAP2 SIP box for the phone + mac: 00:21:29:0c:91:65 + mdns: false + ipv4: + - 10.42.0.10 + bunkerswitch: + description: Switch in the bunkers + mdns: false + ipv4: + - 10.42.0.11 + lathe: + mdns: false + ipv4: + - 10.42.0.12 + infraswitch: + description: Switch for mediaconverting our 10G + mdns: false + ipv4: + - 10.42.0.13 + anna: + mac: 00:e0:c5:6e:d6:8d + ipv4: + - 10.42.1.9 + piscreen2: + description: PixelFlut Raspberry Pi + mac: b8:27:eb:9b:64:d9 + ipv4: + - 10.42.1.12 + pixelfluthafnium: + description: PixelFlut Odroid + mac: 00:1e:06:45:38:08 + ipv4: + - 10.42.1.13 + ipv6: + - 2a01:4262:1ab:b:f100::000d + printbrother: + mac: 00:80:77:06:9f:26 + ipv4: + - 10.42.1.32 + xeroxwax: + mac: 00:00:aa:a7:ef:8b + mdns: false + ipv4: + - 10.42.1.33 + infotron: + description: Infoscreen Raspberry Pi + mac: b8:27:eb:2c:5d:3a + ipv4: + - 10.42.1.34 + spacemon: + mac: b8:27:eb:24:f8:50 + ipv4: + - 10.42.1.35 + jumbotron: + description: Jumbotron Raspberry Pi + mac: b8:27:eb:d3:c1:62 + ipv4: + - 10.42.1.36 + hplaserjet: + mac: 94:57:a5:ce:e2:6c + mdns: false + ipv4: + - 10.42.1.37 + ipv6: + - 2a01:4262:1ab:b:9657:a5ff:fece:e26c + snakeskin: + description: Snakeskin controlling Raspberry Pi + mac: b8:27:eb:9b:64:d9 + ipv4: + - 10.42.1.38 # vim: set ts=2 sw=2 et: -- cgit v1.2.1