summaryrefslogtreecommitdiff
path: root/roles/network/dhcp-server/tasks/main.yml
blob: 90183d9c4f966e88a2656bde0f096e56da89c91e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
- 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 %}