From ea3c05c2b5cd9e0f396787f23a446cfc3b465421 Mon Sep 17 00:00:00 2001 From: Timo Makinen Date: Fri, 13 Jun 2025 13:50:03 +0000 Subject: [PATCH] dhcpd: Move host declarations to global section No need to set host declarations in subnet or shared-network since they are always global and it gives warning during startup: WARNING: Host declarations are global. They are not limited to the scope you declared them in. --- roles/dhcpd/templates/dhcpd.conf.cam.j2 | 14 ++++++-------- roles/dhcpd/templates/dhcpd.conf.j2 | 14 ++++++-------- roles/dhcpd/templates/dhcpd.conf.oob.j2 | 14 ++++++-------- roles/dhcpd/templates/dhcpd.conf.print.j2 | 14 ++++++-------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/roles/dhcpd/templates/dhcpd.conf.cam.j2 b/roles/dhcpd/templates/dhcpd.conf.cam.j2 index 54eff12..b8d3668 100644 --- a/roles/dhcpd/templates/dhcpd.conf.cam.j2 +++ b/roles/dhcpd/templates/dhcpd.conf.cam.j2 @@ -17,7 +17,6 @@ on commit { } shared-network CAMNET { - subnet 172.20.26.0 netmask 255.255.255.0 { default-lease-time 86400; max-lease-time 604800; @@ -28,13 +27,12 @@ shared-network CAMNET { option domain-name-servers 172.20.26.1, 172.20.26.2, 172.20.26.3; use-host-decl-names on; } +} {% for host in ldap_hosts.results %} - host {{ host['cn'] }} { - option host-name "{{ host['cn'] }}"; - hardware ethernet {{ host['macAddress'] }}; - fixed-address {{ host['ipHostNumber'] }}; - } -{% endfor %} - +host {{ host['cn'] }} { + option host-name "{{ host['cn'] }}"; + hardware ethernet {{ host['macAddress'] }}; + fixed-address {{ host['ipHostNumber'] }}; } +{% endfor %} diff --git a/roles/dhcpd/templates/dhcpd.conf.j2 b/roles/dhcpd/templates/dhcpd.conf.j2 index 31cfa87..5ec89f0 100644 --- a/roles/dhcpd/templates/dhcpd.conf.j2 +++ b/roles/dhcpd/templates/dhcpd.conf.j2 @@ -44,7 +44,6 @@ class "OpenBSD" { } shared-network FOOSH { - subnet 172.20.20.0 netmask 255.255.252.0 { default-lease-time 86400; max-lease-time 604800; @@ -56,6 +55,7 @@ shared-network FOOSH { option domain-name-servers 172.20.20.10, 172.20.20.11, 172.20.20.12; use-host-decl-names on; } +} {% for hostname in hostvars %} {% if hostvars[hostname]['network_interfaces'] is defined %} @@ -66,14 +66,12 @@ shared-network FOOSH { {% else %} {% set ipaddr = '172.20.21.' + interface['mac'].split(':')[5] | int(base=16) | string %} {% endif %} - host {{ hostname }} { - option host-name "{{ hostname }}"; - hardware ethernet {{ interface['mac'] }}; - fixed-address {{ ipaddr }}; - } +host {{ hostname }} { + option host-name "{{ hostname }}"; + hardware ethernet {{ interface['mac'] }}; + fixed-address {{ ipaddr }}; +} {% endif %} {% endfor %} {% endif %} {% endfor %} - -} diff --git a/roles/dhcpd/templates/dhcpd.conf.oob.j2 b/roles/dhcpd/templates/dhcpd.conf.oob.j2 index b1a9034..b6e9a2e 100644 --- a/roles/dhcpd/templates/dhcpd.conf.oob.j2 +++ b/roles/dhcpd/templates/dhcpd.conf.oob.j2 @@ -17,7 +17,6 @@ on commit { } shared-network OOBNET { - subnet 172.20.25.0 netmask 255.255.255.0 { default-lease-time 86400; max-lease-time 604800; @@ -28,13 +27,12 @@ shared-network OOBNET { option domain-name-servers 172.20.25.1, 172.20.25.2, 172.20.25.3; use-host-decl-names on; } +} {% for host in ldap_hosts.results %} - host {{ host['cn'] }} { - option host-name "{{ host['cn'] }}"; - hardware ethernet {{ host['macAddress'] }}; - fixed-address {{ host['ipHostNumber'] }}; - } -{% endfor %} - +host {{ host['cn'] }} { + option host-name "{{ host['cn'] }}"; + hardware ethernet {{ host['macAddress'] }}; + fixed-address {{ host['ipHostNumber'] }}; } +{% endfor %} diff --git a/roles/dhcpd/templates/dhcpd.conf.print.j2 b/roles/dhcpd/templates/dhcpd.conf.print.j2 index da5c2e7..dee631d 100644 --- a/roles/dhcpd/templates/dhcpd.conf.print.j2 +++ b/roles/dhcpd/templates/dhcpd.conf.print.j2 @@ -17,7 +17,6 @@ on commit { } shared-network PRINTNET { - subnet 172.20.24.0 netmask 255.255.255.0 { default-lease-time 86400; max-lease-time 604800; @@ -28,13 +27,12 @@ shared-network PRINTNET { option domain-name-servers 172.20.24.1, 172.20.24.2, 172.20.24.3; use-host-decl-names on; } +} {% for host in ldap_hosts.results %} - host {{ host['cn'] }} { - option host-name "{{ host['cn'] }}"; - hardware ethernet {{ host['macAddress'] }}; - fixed-address {{ host['ipHostNumber'] }}; - } -{% endfor %} - +host {{ host['cn'] }} { + option host-name "{{ host['cn'] }}"; + hardware ethernet {{ host['macAddress'] }}; + fixed-address {{ host['ipHostNumber'] }}; } +{% endfor %}