configpolicy/roles/dhcpd/templates/dhcpd.conf.j2

102 lines
2.9 KiB
Django/Jinja

# vim: set ft=dhcpd :
{# vim: set ft=jinja : #}
option space ubnt;
option ubnt.unifi-address code 1 = ip-address;
{% if dhcp_domain_name is defined %}
option domain-name "{{ dhcp_domain_name }}";
{% endif %}
{% if dhcp_dns_servers is defined %}
option domain-name-servers {{ dhcp_dns_servers|join(', ') }};
{% endif %}
{% if dhcp_ntp_servers is defined %}
option ntp-servers {{ dhcp_ntp_servers|join(', ') }};
{% endif %}
authoritative;
{% if dhcp_ddns %}
ddns-updates on;
ddns-update-style interim;
update-static-leases on;
allow client-updates;
{% endif %}
{% for subnet in dhcp_subnets %}
subnet {{ subnet.address|ipv4('network') }} netmask {{ subnet.address|ipv4('netmask') }} {
{% if subnet.pools is defined %}
{% for range in subnet.pools %}
range {{ range.start }} {{ range.end }};
{% endfor %}
{% endif %}
default-lease-time {{ subnet.default_lease|d(dhcp_default_lease) }};
max-lease-time {{ subnet.max_lease|d(dhcp_max_lease) }};
{% if subnet.routers is defined %}
option routers {{ subnet.routers|join(' ') }};
{% endif %}
{% if subnet.domain_name is defined %}
option domain-name "{{ subnet.domain_name }}";
{% endif %}
{% if subnet.domain_search is defined %}
option domain-search "{{ subnet.domain_search }}";
{% endif %}
{% if subnet.dns_servers is defined %}
option domain-name-servers {{ subnet.dns_servers|join(', ') }};
{% endif %}
{% if subnet.ntp_servers is defined %}
option ntp-servers {{ subnet.ntp_servers|join(', ') }};
{% endif %}
{% if subnet.next_server is defined %}
next-server {{ subnet.next_server }};
{% if subnet.boot_filename is defined %}
filename "{{ subnet.boot_filename }}";
{% endif %}
{% endif %}
{% if subnet.unifi_address is defined %}
option ubnt.unifi-address {{ subnet.unifi_address }};
{% endif %}
{% if not subnet.ddns_updates|d(true)|bool %}
ddns-updates off;
{% elif subnet.dynamic_hostnames|d|bool %}
option host-name = {{ dyn_hostname_expr.format(prefix=subnet.dyn_hostname_prefix|d(default_dyn_hostname_prefix)) }};
ddns-hostname = {{ dyn_hostname_expr.format(prefix=subnet.dyn_hostname_prefix|d(default_dyn_hostname_prefix)) }};
{% endif %}
}
{% endfor %}
{% if dhcp_ddns %}
{% for key in dhcp_ddns_keys %}
key {{ key.name }} {
algorithm {{ key.algorithm|d('hmac-md5') }};
secret "{{ key.secret }}";
}
{% endfor %}
{% for zone in dhcp_ddns_zones %}
zone {{ zone.zone }}. {
primary {{ zone.primary }};
{% if zone.key is defined %}
key {{ zone.key }};
{% endif %}
}
{% endfor %}
{% endif %}
{% for res in dhcp_reservations %}
host {{ res.host }} {
{% if res.mac_addr is defined %}
hardware ethernet {{ res.mac_addr }};
{% elif res.duid is defined %}
host-identifier option dhcp-client-identifier {{ res.duid }};
{% endif %}
{% if res.ip_addr is defined %}
fixed-address {{ res.ip_addr }};
{% endif %}
{% if res.hostname is defined %}
option host-name "{{ res.hostname }}";
ddns-hostname "{{ res.hostname }}";
{% endif %}
}
{% endfor %}