# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

- name: Create the dhcp template
  copy:
    src: "{{ role_path }}/files/temp_dhcp.template"
    dest: "{{ role_path }}/files/dhcpd.conf"
    mode: 0775
  tags: install

- name: Assign subnet and netmask
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^subnet subnet_mask netmask net_mask {'
    replace: 'subnet {{ mngmnt_network_subnet }} netmask {{ mngmnt_network_netmask }} {'
  tags: install

- name: Assign netmask
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^option subnet-mask net_mask;'
    replace: 'option subnet-mask {{ mngmnt_network_netmask }};'

- name: Assign DHCP range
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^range dynamic-bootp start end;'
    replace: 'range dynamic-bootp {{ mngmnt_network_dhcp_start_range }} {{ mngmnt_network_dhcp_end_range }};'

- name: Assign default lease time
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^default-lease-time default;'
    replace: 'default-lease-time {{ default_lease_time }};'
    
- name: Assign max lease time
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^max-lease-time max;'
    replace: 'max-lease-time {{ max_lease_time }};'

- name: Assign next server range
  replace:
    path: "{{ role_path }}/files/dhcpd.conf"
    regexp: '^next-server next_server;'
    replace: 'next-server {{ mngmnt_network_ip }};'
