blob: 56fafb5b6d6a62c2042f68796fc223c2c088293f [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
{% if ansible_system == "Linux" %}
option rfc3442-classless-static-routes code 121 = array of integer 8;
{% endif %}
{% for subnet, subdata in dhcpd_subnets.items() %}
subnet {{ subnet | ipaddr('network') }} netmask {{ subnet | ipaddr('netmask') }} {
# routing
{% if subdata.routers is defined %}
# custom router IP set
option routers {{ subdata.routers | map(attribute="ip") | join (",") }};
{% set r3442ns = namespace(r3442list = []) %}
{% for rtr in subdata.routers %}
{% if "rfc3442routes" in rtr %}
{% set r3442ns.r3442list = r3442ns.r3442list + (rtr | rfc3442_words() ) %}
{% endif %}
{% endfor %}
{% if r3442ns.r3442list %}
option rfc3442-classless-static-routes {{ r3442ns.r3442list | join(', ') }};
{% endif %}
{% else %}
# first IP address in range used as router
option routers {{ subnet | ipaddr('next_usable') }};
{% endif %}
# DNS/naming options
option domain-name-servers {{ subdata.dns_servers | join(", ") }};
option domain-name "{{ subdata.dns_search [0] }}";
option domain-search "{{ subdata.dns_search | join('", "') }}";
{% if subdata.tftpd_server is defined and subdata.tftpd_server %}
# tftpd options
filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
next-server {{ subdata.tftpd_server }};
{% endif %}
{% if subdata.ntp_servers is defined and subdata.ntp_servers %}
# ntp options
option ntp-servers {{ subdata.ntp_servers | join('", "') }};
{% endif %}
{% if subdata.range is defined %}
# dynamically assignable range
range {{ subdata.range | ipaddr('next_usable') }} {{ subdata.range | ipaddr('last_usable') }};
{% endif %}
}
{% if subdata.hosts is defined %}
# hosts for subnet: {{ subdata.dns_search [0] }}
{% for host in subdata.hosts %}
host {{ host.name }}.{{ subdata.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 %}