- name: Install dhcp package (debuntu)
  package:
    name: isc-dhcp-server
    state: present
  when: is_debuntu
  tags:
    - download

- name: Install dhcp package (not debuntu)
  package:
    name: dhcp
    state: present
  when: not is_debuntu
  tags:
    - download

- name: Create non-privileged user 'dhcpd' (debuntu)
  user:
    name: dhcpd
    createhome: no
  when: is_debuntu

- name: Disable stock dhcp_service (debuntu)
  service:
    name: "{{ dhcp_service }}"
    enabled: no
    state: stopped
  when: is_debuntu

- name: Disable stock dhcp_service ipv6 (ubuntu-18)
  service:
    name: "{{ dhcp_service }}6"
    enabled: no
    state: stopped
  when: is_ubuntu_18

- name: Install systemd unit file to /etc/systemd/system/dhcpd.service
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  with_items:
   - { src: 'roles/network/templates/dhcp/dhcpd.service', dest: '/etc/systemd/system/dhcpd.service', mode: '0644' }

- name: Create file /var/lib/dhcpd/dhcpd.leases (redhat)
  command: touch /var/lib/dhcpd/dhcpd.leases
  args:
    creates: /var/lib/dhcpd/dhcpd.leases
  when: is_redhat

- name: Set dhcpd.leases permissions/ownership (redhat)
  file:
    path: /var/lib/dhcpd/dhcpd.leases
    owner: dhcpd
    group: dhcpd
    mode: 0644
    state: file
  when: is_redhat
