Initial commit of dhcpd/tftpd role
Change-Id: Ia6526e593100c9bbe935347105c5b3932f5e2641
diff --git a/templates/dhcpd.conf.j2 b/templates/dhcpd.conf.j2
new file mode 100644
index 0000000..2ed3420
--- /dev/null
+++ b/templates/dhcpd.conf.j2
@@ -0,0 +1,54 @@
+# 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") }};
+
+{% for subnet in dhcpd_subnets %}
+subnet {{ subnet.subnet | ipaddr('network') }} netmask {{ subnet.subnet | ipaddr('netmask') }} {
+
+ # routing
+{% if subnet.routers is defined %}
+ option routers {{ subnet.routers }};
+{% else %}
+ option routers {{ subnet.subnet | ipaddr('next_usable') }};
+{% endif %}
+
+ # DNS/naming options
+ option domain-name-servers {{ subnet.dns_servers | join(", ") }};
+ option domain-name "{{ subnet.dns_search [0] }}";
+ option domain-search "{{ subnet.dns_search | join('", "') }}";
+
+{% if subnet.tftpd_server is defined %}
+ # tftpd options
+ filename "{{ subnet.pxe_filename | default(dhcpd_pxe_filename) }}";
+ next-server {{ subnet.tftpd_server }};
+
+{% endif %}
+{% if subnet.range is defined %}
+ range {{ subnet.range | ipaddr('next_usable') }} {{ subnet.range | ipaddr('last_usable') }};
+
+{% endif %}
+{% if subnet.hosts is defined %}
+ # hosts
+{% for host in subnet.hosts %}
+ host {{ host.name }} {
+ 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 %}