| # 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") }}; |
| |
| # ignore client UID data, which can lead to duplicate leases |
| ignore-client-uids true; |
| |
| # option definitions |
| {% if ansible_system != "OpenBSD" %} |
| option rfc3442-classless-static-routes code 121 = array of integer 8; |
| option client-arch code 93 = unsigned integer 16; # RFC4578 |
| {% 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 |
| {% if ansible_system == "OpenBSD" %} |
| filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}"; |
| {% else %} |
| if option client-arch = 00:07 { |
| # amd64 EFI boot |
| filename "{{ subdata.efi_filename | default(dhcpd_efi_filename) }}"; |
| } else { |
| # BIOS boot |
| filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}"; |
| } |
| {% endif %} |
| 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 %} |