blob: fda60b7eed082300a22a04c72458f9ff8437e36c [file] [log] [blame]
Zack Williams9fc21d72020-11-22 22:36:54 -07001# dhcpd templates/dhcpd.conf.j2 - {{ ansible_managed }}
2{#
3SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
4SPDX-License-Identifier: Apache-2.0
5#}
6
7# global lease options
8default-lease-time {{ subnet.lease_time | default("240") }};
9max-lease-time {{ subnet.max_lease_time | default("480") }};
10
Zack Williamsc1d528f2020-12-09 13:25:18 -070011# option definitions
Zack Williams5101b5f2022-05-17 13:30:01 -070012{% if ansible_system != "OpenBSD" %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070013option rfc3442-classless-static-routes code 121 = array of integer 8;
Zack Williams5101b5f2022-05-17 13:30:01 -070014option client-arch code 93 = unsigned integer 16; # RFC4578
Zack Williams98725e22021-03-18 10:21:26 -070015{% endif %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070016
Zack Williams7f58df02021-09-14 13:49:57 -070017{% for subnet, subdata in dhcpd_subnets.items() %}
18subnet {{ subnet | ipaddr('network') }} netmask {{ subnet | ipaddr('netmask') }} {
Zack Williams9fc21d72020-11-22 22:36:54 -070019
20 # routing
Zack Williams7f58df02021-09-14 13:49:57 -070021{% if subdata.routers is defined %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070022 # custom router IP set
Zack Williams7f58df02021-09-14 13:49:57 -070023 option routers {{ subdata.routers | map(attribute="ip") | join (",") }};
Zack Williams98725e22021-03-18 10:21:26 -070024{% set r3442ns = namespace(r3442list = []) %}
Zack Williams7f58df02021-09-14 13:49:57 -070025{% for rtr in subdata.routers %}
Zack Williams65ee5d02020-12-14 20:57:00 -070026{% if "rfc3442routes" in rtr %}
Zack Williams98725e22021-03-18 10:21:26 -070027{% set r3442ns.r3442list = r3442ns.r3442list + (rtr | rfc3442_words() ) %}
Zack Williams65ee5d02020-12-14 20:57:00 -070028{% endif %}
29{% endfor %}
Zack Williams98725e22021-03-18 10:21:26 -070030{% if r3442ns.r3442list %}
31 option rfc3442-classless-static-routes {{ r3442ns.r3442list | join(', ') }};
32{% endif %}
Zack Williams9fc21d72020-11-22 22:36:54 -070033{% else %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070034 # first IP address in range used as router
Zack Williams7f58df02021-09-14 13:49:57 -070035 option routers {{ subnet | ipaddr('next_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070036{% endif %}
37
38 # DNS/naming options
Zack Williams7f58df02021-09-14 13:49:57 -070039 option domain-name-servers {{ subdata.dns_servers | join(", ") }};
40 option domain-name "{{ subdata.dns_search [0] }}";
41 option domain-search "{{ subdata.dns_search | join('", "') }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070042
Zack Williams7f58df02021-09-14 13:49:57 -070043{% if subdata.tftpd_server is defined and subdata.tftpd_server %}
Zack Williams9fc21d72020-11-22 22:36:54 -070044 # tftpd options
Zack Williams5101b5f2022-05-17 13:30:01 -070045{% if ansible_system == "OpenBSD" %}
Zack Williams7f58df02021-09-14 13:49:57 -070046 filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
Zack Williams5101b5f2022-05-17 13:30:01 -070047{% else %}
48 if option client-arch = 00:07 {
49 # amd64 EFI boot
50 filename "{{ subdata.efi_filename | default(dhcpd_efi_filename) }}";
51 } else {
52 # BIOS boot
53 filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
54 }
55{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070056 next-server {{ subdata.tftpd_server }};
Zack Williams9fc21d72020-11-22 22:36:54 -070057
58{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070059{% if subdata.ntp_servers is defined and subdata.ntp_servers %}
Zack Williams98725e22021-03-18 10:21:26 -070060 # ntp options
Zack Williams7f58df02021-09-14 13:49:57 -070061 option ntp-servers {{ subdata.ntp_servers | join('", "') }};
Zack Williams98725e22021-03-18 10:21:26 -070062
63{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070064{% if subdata.range is defined %}
Zack Williams98725e22021-03-18 10:21:26 -070065 # dynamically assignable range
Zack Williams7f58df02021-09-14 13:49:57 -070066 range {{ subdata.range | ipaddr('next_usable') }} {{ subdata.range | ipaddr('last_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070067{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070068}
69
Zack Williams7f58df02021-09-14 13:49:57 -070070{% if subdata.hosts is defined %}
71# hosts for subnet: {{ subdata.dns_search [0] }}
72{% for host in subdata.hosts %}
73host {{ host.name }}.{{ subdata.dns_search [0] }} {
Zack Williamsbd970272020-11-30 22:59:00 -070074 option host-name "{{ host.name }}";
75 fixed-address {{ host.ip_addr }};
76 hardware ethernet {{ host.mac_addr | hwaddr('linux') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070077{% if host.pxe_filename is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070078 filename "{{ host.pxe_filename }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070079{% endif %}
80{% if host.default_url is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070081 option default-url "{{ host.default_url }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070082{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070083}
Zack Williams9fc21d72020-11-22 22:36:54 -070084
85{% endfor %}
86{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070087
Zack Williams9fc21d72020-11-22 22:36:54 -070088{% endfor %}