blob: 3951fe50dd3950176c7df519a116f26ee3820981 [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 Williams98725e22021-03-18 10:21:26 -070012{% if ansible_system == "Linux" %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070013option rfc3442-classless-static-routes code 121 = array of integer 8;
Zack Williams98725e22021-03-18 10:21:26 -070014{% endif %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070015
Zack Williams9fc21d72020-11-22 22:36:54 -070016{% for subnet in dhcpd_subnets %}
17subnet {{ subnet.subnet | ipaddr('network') }} netmask {{ subnet.subnet | ipaddr('netmask') }} {
18
19 # routing
20{% if subnet.routers is defined %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070021 # custom router IP set
Zack Williams65ee5d02020-12-14 20:57:00 -070022 option routers {{ subnet.routers | map(attribute="ip") | join (",") }};
Zack Williams98725e22021-03-18 10:21:26 -070023{% set r3442ns = namespace(r3442list = []) %}
Zack Williams65ee5d02020-12-14 20:57:00 -070024{% for rtr in subnet.routers %}
25{% if "rfc3442routes" in rtr %}
Zack Williams98725e22021-03-18 10:21:26 -070026{% set r3442ns.r3442list = r3442ns.r3442list + (rtr | rfc3442_words() ) %}
Zack Williams65ee5d02020-12-14 20:57:00 -070027{% endif %}
28{% endfor %}
Zack Williams98725e22021-03-18 10:21:26 -070029{% if r3442ns.r3442list %}
30 option rfc3442-classless-static-routes {{ r3442ns.r3442list | join(', ') }};
31{% endif %}
Zack Williams9fc21d72020-11-22 22:36:54 -070032{% else %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070033 # first IP address in range used as router
Zack Williams9fc21d72020-11-22 22:36:54 -070034 option routers {{ subnet.subnet | ipaddr('next_usable') }};
35{% endif %}
36
37 # DNS/naming options
38 option domain-name-servers {{ subnet.dns_servers | join(", ") }};
39 option domain-name "{{ subnet.dns_search [0] }}";
40 option domain-search "{{ subnet.dns_search | join('", "') }}";
41
42{% if subnet.tftpd_server is defined %}
43 # tftpd options
44 filename "{{ subnet.pxe_filename | default(dhcpd_pxe_filename) }}";
45 next-server {{ subnet.tftpd_server }};
46
47{% endif %}
Zack Williams98725e22021-03-18 10:21:26 -070048{% if subnet.ntp_servers is defined %}
49 # ntp options
50 option ntp-servers {{ subnet.ntp_servers | join('", "') }};
51
52{% endif %}
Zack Williams9fc21d72020-11-22 22:36:54 -070053{% if subnet.range is defined %}
Zack Williams98725e22021-03-18 10:21:26 -070054 # dynamically assignable range
Zack Williams9fc21d72020-11-22 22:36:54 -070055 range {{ subnet.range | ipaddr('next_usable') }} {{ subnet.range | ipaddr('last_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070056{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070057}
58
Zack Williams9fc21d72020-11-22 22:36:54 -070059{% if subnet.hosts is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070060# hosts for subnet: {{ subnet.dns_search [0] }}
Zack Williams9fc21d72020-11-22 22:36:54 -070061{% for host in subnet.hosts %}
Zack Williamsbd970272020-11-30 22:59:00 -070062host {{ host.name }}.{{ subnet.dns_search [0] }} {
63 option host-name "{{ host.name }}";
64 fixed-address {{ host.ip_addr }};
65 hardware ethernet {{ host.mac_addr | hwaddr('linux') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070066{% if host.pxe_filename is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070067 filename "{{ host.pxe_filename }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070068{% endif %}
69{% if host.default_url is defined %}
Zack Williamsbd970272020-11-30 22:59:00 -070070 option default-url "{{ host.default_url }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070071{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070072}
Zack Williams9fc21d72020-11-22 22:36:54 -070073
74{% endfor %}
75{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070076
Zack Williams9fc21d72020-11-22 22:36:54 -070077{% endfor %}