blob: bda9becc61cdb6d46bd9cb5b0f055a7cc45d72cb [file] [log] [blame]
# dhcpd templates/dhcpd.conf.j2 - {{ ansible_managed }}
{#
SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
SPDX-License-Identifier: Apache-2.0
#}
# global lease options
default-lease-time {{ subnet.lease_time | default("240") }};
max-lease-time {{ subnet.max_lease_time | default("480") }};
# option definitions
option rfc3442-classless-static-routes code 121 = array of integer 8;
{% for subnet in dhcpd_subnets %}
subnet {{ subnet.subnet | ipaddr('network') }} netmask {{ subnet.subnet | ipaddr('netmask') }} {
# routing
{% if subnet.routers is defined %}
# custom router IP set
option routers {{ subnet.routers | map(attribute="ip") | join (",") }};
{% for rtr in subnet.routers %}
{% if "rfc3442routes" in rtr %}
{% for r3442r in rtr.rfc3442routes %}
option rfc3442-classless-static-routes {{ r3442r | ipaddr('prefix') }}, {{ r3442r | ipaddr('network') | regex_replace('\.', ', ')}}, {{ rtr.ip | ipaddr('network') | regex_replace('\.', ', ')}};
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
# first IP address in range used as router
option routers {{ subnet.subnet | ipaddr('next_usable') }};
{% endif %}
# DNS/naming options
option domain-name-servers {{ subnet.dns_servers | join(", ") }};
option domain-name "{{ subnet.dns_search [0] }}";
option domain-search "{{ subnet.dns_search | join('", "') }}";
{% if subnet.tftpd_server is defined %}
# tftpd options
filename "{{ subnet.pxe_filename | default(dhcpd_pxe_filename) }}";
next-server {{ subnet.tftpd_server }};
{% endif %}
{% if subnet.range is defined %}
range {{ subnet.range | ipaddr('next_usable') }} {{ subnet.range | ipaddr('last_usable') }};
{% endif %}
}
{% if subnet.hosts is defined %}
# hosts for subnet: {{ subnet.dns_search [0] }}
{% for host in subnet.hosts %}
host {{ host.name }}.{{ subnet.dns_search [0] }} {
option host-name "{{ host.name }}";
fixed-address {{ host.ip_addr }};
hardware ethernet {{ host.mac_addr | hwaddr('linux') }};
{% if host.pxe_filename is defined %}
filename "{{ host.pxe_filename }}";
{% endif %}
{% if host.default_url is defined %}
option default-url "{{ host.default_url }}";
{% endif %}
}
{% endfor %}
{% endif %}
{% endfor %}