--- - name: install isc-dhcp-server apt: name: isc-dhcp-server state: present - name: configure interfaces lineinfile: path: /etc/default/isc-dhcp-server regexp: '^INTERFACESv4=' line: "INTERFACESv4=\"{{ dhcp_server_interfaces | list | sort | join(' ') }}\"" notify: restart isc-dhcp-server - name: configure subnets blockinfile: path: /etc/dhcp/dhcpd.conf marker: '### {mark} ansible network/dhcp-server subnets ###' block: | {% for interface,subnet in dhcp_server_interfaces.items() %} subnet {{ subnet.prefix | ansible.utils.ipaddr('network') }} netmask {{ subnet.prefix | ansible.utils.ipaddr('netmask') }} { range {{ subnet.prefix | ansible.utils.ipaddr(subnet.start) | ansible.utils.ipaddr('address') }} {{ subnet.prefix | ansible.utils.ipaddr(subnet.limit) | ansible.utils.ipaddr('address') }}; {% if 'gateway' in subnet %} option routers {{ subnet.gateway }}; {% endif %} {% if 'dns' in subnet %} option domain-name-servers {{ subnet.dns | join(', ') }}; {% endif %} {% if 'domain' in subnet %} option domain-name "{{ subnet.domain }}"; {% endif %} } {% if not loop.last %} {% endif %} {% endfor %}