#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install dhcp-server
  apt:
    pkg:
    - isc-dhcp-server
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: set interfaces to serve
  lineinfile:
    name: /etc/default/isc-dhcp-server
    regexp: '^INTERFACESv4='
    line: 'INTERFACESv4="{{dhcpd_interfaces}}"'


- name: copy dhcpd.conf
  copy:
    src: "{{item}}"
    dest: "/etc/dhcp/dhcpd.conf"
    mode: 0640
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/dhcpd.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/dhcpd.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/dhcpd.conf"
    - "default/dhcpd.conf"
  notify: restart isc-dhcp-server.service


- name: enable and start isc-dhcp-server.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: isc-dhcp-server.service
