blob: 56fafb5b6d6a62c2042f68796fc223c2c088293f [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 Williams7f58df02021-09-14 13:49:57 -070016{% for subnet, subdata in dhcpd_subnets.items() %}
17subnet {{ subnet | ipaddr('network') }} netmask {{ subnet | ipaddr('netmask') }} {
Zack Williams9fc21d72020-11-22 22:36:54 -070018
19 # routing
Zack Williams7f58df02021-09-14 13:49:57 -070020{% if subdata.routers is defined %}
Zack Williamsc1d528f2020-12-09 13:25:18 -070021 # custom router IP set
Zack Williams7f58df02021-09-14 13:49:57 -070022 option routers {{ subdata.routers | map(attribute="ip") | join (",") }};
Zack Williams98725e22021-03-18 10:21:26 -070023{% set r3442ns = namespace(r3442list = []) %}
Zack Williams7f58df02021-09-14 13:49:57 -070024{% for rtr in subdata.routers %}
Zack Williams65ee5d02020-12-14 20:57:00 -070025{% 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 Williams7f58df02021-09-14 13:49:57 -070034 option routers {{ subnet | ipaddr('next_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070035{% endif %}
36
37 # DNS/naming options
Zack Williams7f58df02021-09-14 13:49:57 -070038 option domain-name-servers {{ subdata.dns_servers | join(", ") }};
39 option domain-name "{{ subdata.dns_search [0] }}";
40 option domain-search "{{ subdata.dns_search | join('", "') }}";
Zack Williams9fc21d72020-11-22 22:36:54 -070041
Zack Williams7f58df02021-09-14 13:49:57 -070042{% if subdata.tftpd_server is defined and subdata.tftpd_server %}
Zack Williams9fc21d72020-11-22 22:36:54 -070043 # tftpd options
Zack Williams7f58df02021-09-14 13:49:57 -070044 filename "{{ subdata.pxe_filename | default(dhcpd_pxe_filename) }}";
45 next-server {{ subdata.tftpd_server }};
Zack Williams9fc21d72020-11-22 22:36:54 -070046
47{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070048{% if subdata.ntp_servers is defined and subdata.ntp_servers %}
Zack Williams98725e22021-03-18 10:21:26 -070049 # ntp options
Zack Williams7f58df02021-09-14 13:49:57 -070050 option ntp-servers {{ subdata.ntp_servers | join('", "') }};
Zack Williams98725e22021-03-18 10:21:26 -070051
52{% endif %}
Zack Williams7f58df02021-09-14 13:49:57 -070053{% if subdata.range is defined %}
Zack Williams98725e22021-03-18 10:21:26 -070054 # dynamically assignable range
Zack Williams7f58df02021-09-14 13:49:57 -070055 range {{ subdata.range | ipaddr('next_usable') }} {{ subdata.range | ipaddr('last_usable') }};
Zack Williams9fc21d72020-11-22 22:36:54 -070056{% endif %}
Zack Williamsbd970272020-11-30 22:59:00 -070057}
58
Zack Williams7f58df02021-09-14 13:49:57 -070059{% if subdata.hosts is defined %}
60# hosts for subnet: {{ subdata.dns_search [0] }}
61{% for host in subdata.hosts %}
62host {{ host.name }}.{{ subdata.dns_search [0] }} {
Zack Williamsbd970272020-11-30 22:59:00 -070063 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 %}