# dhcpd.conf

{{ ansible_header | comment }}

{% for option in dhcp.global_options %}
option {{ option.key }} {{ option.value }};
{% endfor %}

{% for parameter in dhcp.global_parameters %}
{{ parameter.key }} {{ parameter.value }};
{% endfor %}

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
{% if dhcp.authoritative %}
authoritative;
{% else %}
#authoritative;
{% endif %}

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;


{% if dhcp.failover is defined %}
include "./dhcp-failover.conf";
{% endif %}


{% for subnet in dhcp.subnets %}
subnet {{ subnet.network | ipaddr('network') }} netmask {{ subnet.network | ipaddr('netmask') }} {
	interface "{{ interfaces[subnet.vlan]  }}";
{% if subnet.default_lease_time is defined %}
	default-lease-time {{ subnet.default_lease_time }};
{% endif %}
{% if subnet.max_lease_time is defined %}
	max-lease-time {{ subnet.max_lease_time }};
{% endif %}
	option subnet-mask {{ subnet.network | ipaddr('netmask') }};
	option broadcast-address {{ subnet.network | ipaddr('broadcast') }};
{% if subnet.routers is defined %}
	option routers {{ subnet.routers }};
{% endif %}
	option domain-name-servers {{ subnet.dns | join(", ") }};
	option domain-name "{{ subnet.domain_name }}";
	option domain-search "{{ subnet.domain_search }}";
{% for option in subnet.options %}
	option {{ option.key }} {{ option.value }};
{% endfor %}
{% if subnet.lease_file is defined %}
	include "{{ subnet.lease_file }}";
{% endif %}
{% if subnet.ranges is defined %}
	pool {
  {% if dhcp.failover is defined %}
		failover peer {{ dhcp.failover.name }}
  {% endif %}
{% for pool in subnet.ranges %}
		range {{ pool.min }} {{ pool.max }};
{% endfor %}
	}
  {% endif %}

{% if subnet.deny_unknown is defined and subnet.deny_unknown %}
	deny unknown-clients;
{% else %}
	allow unknown-clients;
{% endif %}
}
{% endfor %}