blob: 31ea762bfbe431cc9b916bc7d802b3fb25870f6d [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 Williams7ae01702022-11-29 10:09:14 -070011# ignore client UID data, which can lead to duplicate leases
12ignore-client-uids true;
13
Zack Williamsc1d528f2020-12-09 13:25:18 -070014# option definitions
Zack Williams5101b5f2022-05-17 13:30:01 -070015{% if ansible_system != "OpenBSD" %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070016option rfc3442-classless-static-routes code 121 = array of integer 8;
Zack Williams5101b5f2022-05-17 13:30:01 -070017option client-arch code 93 = unsigned integer 16; # RFC4578
Zack Williams98725e22021-03-18 10:21:26 -070018{% endif %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070019
Zack Williams7f58df02021-09-14 13:49:57 -070020{% for subnet, subdata in dhcpd_subnets.items() %}
21subnet {{ subnet | ipaddr('network') }} netmask {{ subnet | ipaddr('netmask') }} {
Zack Williams9fc21d72020-11-22 22:36:54 -070022
23 # routing
Zack Williams7f58df02021-09-14 13:49:57 -070024{% if subdata.routers is defined %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070025 # custom router IP set
Zack Williams7f58df02021-09-14 13:49:57 -070026 option routers {{ subdata.routers | map(attribute="ip") | join (",") }};
Zack Williams98725e22021-03-18 10:21:26 -070027{% set r3442ns = namespace(r3442list = []) %}
Zack Williams7f58df02021-09-14 13:49:57 -070028{% for rtr in subdata.routers %}
Zack Williams65ee5d02020-12-14 20:57:00 -070029{% if "rfc3442routes" in rtr %}
Zack Williams98725e22021-03-18 10:21:26 -070030{% set r3442ns.r3442list = r3442ns.r3442list + (rtr | rfc3442_words() ) %}
Zack Williams65ee5d02020-12-14 20:57:00 -070031{% endif %}
32{% endfor %}
Zack Williams98725e22021-03-18 10:21:26 -070033{% if r3442ns.r3442list %}
34 option rfc3442-classless-static-routes {{ r3442ns.r3442list | join(', ') }};
35{% endif %}
Zack Williams9fc21d72020-11-22 22:36:54 -070036{% else %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070037 # first IP address in range used as router
Zack Williams7f58df02021-09-14 13:49:57 -070038 option routers {{ subnet | ipaddr('next_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070039{% endif %}
40
41 # DNS/naming options
Zack Williams7f58df02021-09-14 13:49:57 -070042 option domain-name-servers {{ subdata.dns_servers | join(", ") }};
43 option domain-name "{{ subdata.dns_search [0] }}";
44 option domain-search "{{ subdata.dns_search | join('", "') }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070045
Zack Williams7f58df02021-09-14 13:49:57 -070046{% if subdata.tftpd_server is defined and subdata.tftpd_server %}
Zack Williams9fc21d72020-11-22 22:36:54 -070047 # tftpd options
Zack Williams5101b5f2022-05-17 13:30:01 -070048{% if ansible_system == "OpenBSD" %}
Zack Williams7f58df02021-09-14 13:49:57 -070049 filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
Zack Williams5101b5f2022-05-17 13:30:01 -070050{% else %}
51 if option client-arch = 00:07 {
52 # amd64 EFI boot
53 filename "{{ subdata.efi_filename | default(dhcpd_efi_filename) }}";
54 } else {
55 # BIOS boot
56 filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
57 }
58{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070059 next-server {{ subdata.tftpd_server }};
Zack Williams9fc21d72020-11-22 22:36:54 -070060
61{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070062{% if subdata.ntp_servers is defined and subdata.ntp_servers %}
Zack Williams98725e22021-03-18 10:21:26 -070063 # ntp options
Zack Williams7f58df02021-09-14 13:49:57 -070064 option ntp-servers {{ subdata.ntp_servers | join('", "') }};
Zack Williams98725e22021-03-18 10:21:26 -070065
66{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070067{% if subdata.range is defined %}
Zack Williams98725e22021-03-18 10:21:26 -070068 # dynamically assignable range
Zack Williams7f58df02021-09-14 13:49:57 -070069 range {{ subdata.range | ipaddr('next_usable') }} {{ subdata.range | ipaddr('last_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070070{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070071}
72
Zack Williams7f58df02021-09-14 13:49:57 -070073{% if subdata.hosts is defined %}
74# hosts for subnet: {{ subdata.dns_search [0] }}
75{% for host in subdata.hosts %}
76host {{ host.name }}.{{ subdata.dns_search [0] }} {
Zack Williamsbd970272020-11-30 22:59:00 -070077 option host-name "{{ host.name }}";
78 fixed-address {{ host.ip_addr }};
79 hardware ethernet {{ host.mac_addr | hwaddr('linux') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070080{% if host.pxe_filename is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070081 filename "{{ host.pxe_filename }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070082{% endif %}
83{% if host.default_url is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070084 option default-url "{{ host.default_url }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070085{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070086}
Zack Williams9fc21d72020-11-22 22:36:54 -070087
88{% endfor %}
89{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070090
Zack Williams9fc21d72020-11-22 22:36:54 -070091{% endfor %}