From af333f0ec23a9784756a8b0e53a9896d7f61525f Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Mon, 1 Apr 2019 12:34:26 +0200 Subject: space_server: vars: rework local_hosts ..to get rid of the need for ipv4/ipv6 filters and python-netaddr dependency. --- roles/space_server/bootstrap.sh | 2 +- roles/space_server/templates/avahi-hosts.j2 | 20 +++++++++++-------- roles/space_server/templates/dhcpd.conf.j2 | 4 ++-- roles/space_server/templates/s.zone.j2 | 10 +++++++--- roles/space_server/vars/main.yml | 30 ++++++++++++++--------------- 5 files changed, 37 insertions(+), 29 deletions(-) (limited to 'roles') diff --git a/roles/space_server/bootstrap.sh b/roles/space_server/bootstrap.sh index dae4460..6d09592 100755 --- a/roles/space_server/bootstrap.sh +++ b/roles/space_server/bootstrap.sh @@ -59,7 +59,7 @@ dnf \ --disablerepo='*' \ --enablerepo=fedora \ --enablerepo=updates \ - install glibc-langpack-en dnf git ansible python3-netaddr python-unversioned-command + install glibc-langpack-en dnf git ansible python-unversioned-command if [[ -f "$secrets" ]]; then install -m660 "$secrets" "$dest$secrets" diff --git a/roles/space_server/templates/avahi-hosts.j2 b/roles/space_server/templates/avahi-hosts.j2 index f87ad4b..1e371e6 100644 --- a/roles/space_server/templates/avahi-hosts.j2 +++ b/roles/space_server/templates/avahi-hosts.j2 @@ -1,14 +1,18 @@ {% for host in local_hosts %} {% if 'mdns' not in host or host.mdns %} -{% for ip in host.ips | ipv4 %} -{% if loop.index <= 1 %} +{% if 'ipv4' in host %} +{% for ip in host.ipv4 %} +{% if loop.index <= 1 %} {{ ip }} {{ host.name }}.local -{% endif %} -{% endfor %} -{% for ip in host.ips | ipv6 %} -{% if loop.index <= 1 %} +{% endif %} +{% endfor %} +{% endif %} +{% if 'ipv6' in host %} +{% for ip in host.ipv6 %} +{% if loop.index <= 1 %} {{ ip }} {{ host.name }}.local -{% endif %} -{% endfor %} +{% endif %} +{% endfor %} +{% endif %} {% endif %} {% endfor %} diff --git a/roles/space_server/templates/dhcpd.conf.j2 b/roles/space_server/templates/dhcpd.conf.j2 index e071a88..23e08da 100644 --- a/roles/space_server/templates/dhcpd.conf.j2 +++ b/roles/space_server/templates/dhcpd.conf.j2 @@ -105,14 +105,14 @@ subnet 10.42.3.0 netmask 255.255.255.0 { group { use-host-decl-names on; {% for host in local_hosts %} +{% if 'mac' in host and 'ipv4' in host %} -{% if 'mac' in host %} {% if 'description' in host %} # {{ host.description }} {% endif %} host {{ host.name }} { hardware ethernet {{ host.mac }}; - fixed-address {{ host.ips | first }}; + fixed-address {{ host.ipv4|join(', ') }}; {% if 'filename' in host %} filename "{{ host.filename }}"; {% endif %} diff --git a/roles/space_server/templates/s.zone.j2 b/roles/space_server/templates/s.zone.j2 index 6bf9718..a392f3d 100644 --- a/roles/space_server/templates/s.zone.j2 +++ b/roles/space_server/templates/s.zone.j2 @@ -9,13 +9,17 @@ 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 %} -{% if 'ips' in host and host.ips|length > 0 %} -{% for ip in host.ips|ipv4 %} +{% if 'ipv4' in host %} +{% for ip in host.ipv4 %} {{ host.name }}.s. 600 IN A {{ ip }} {% endfor %} -{% for ip in host.ips|ipv6 %} +{% endif %} +{% if 'ipv6' in host %} +{% for ip in host.ipv6 %} {{ host.name }}.s. 600 IN AAAA {{ ip }} {% endfor %} {% endif %} +{% endif %} {% endfor %} diff --git a/roles/space_server/vars/main.yml b/roles/space_server/vars/main.yml index 1914374..387a7c9 100644 --- a/roles/space_server/vars/main.yml +++ b/roles/space_server/vars/main.yml @@ -20,7 +20,6 @@ dnf_packages: 'dosfstools': present 'btrfs-progs': present 'ansible': present - 'python3-netaddr': present # for avahi-hosts template 'git': present 'htop': present 'man-db': present @@ -64,67 +63,68 @@ local_hosts: description: Front door controlling Raspberry Pi mac: b8:27:eb:d9:92:00 mdns: false - ips: + ipv4: - 10.42.0.3 - name: foodputer mac: 00:d0:59:37:5e:37 mdns: false - ips: + ipv4: - 10.42.0.4 - name: ap1 mdns: false - ips: + ipv4: - 10.42.0.5 - name: ap2 mdns: false - ips: + ipv4: - 10.42.0.6 - name: switch mac: 00:1b:11:6f:42:f8 mdns: false - ips: + ipv4: - 10.42.0.9 - name: lathe mdns: false - ips: + ipv4: - 10.42.0.12 - name: anna mac: 00:e0:c5:6e:d6:8d - ips: + ipv4: - 10.42.1.9 - name: printbrother mac: 00:80:77:06:9f:26 - ips: + ipv4: - 10.42.1.32 - name: xeroxwax mac: 00:00:aa:a7:ef:8b mdns: false - ips: + ipv4: - 10.42.1.33 - name: infotron description: Infoscreen Raspberry Pi mac: b8:27:eb:2c:5d:3a - ips: + ipv4: - 10.42.1.34 - name: spacemon mac: b8:27:eb:24:f8:50 - ips: + ipv4: - 10.42.1.35 - name: jumbotron description: Jumbotron Raspberry Pi mac: b8:27:eb:d3:c1:62 - ips: + ipv4: - 10.42.1.36 - name: hplaserjet mac: 94:57:a5:ce:e2:6c mdns: false - ips: + 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 - ips: + ipv4: - 10.42.1.38 # vim: set ts=2 sw=2 et: -- cgit v1.2.1