diff --git a/README.md b/README.md index 779cab489..8e900fcc0 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,12 @@ Create host reservations. May be passed as a hash into the DHCP class. ```puppet dhcp::host { 'server1': - comment => 'Optional descriptive comment', - mac => '00:50:56:00:00:01', - ip => '10.0.1.51', + comment => 'Optional descriptive comment', + mac => '00:50:56:00:00:01', + ip => '10.0.1.51', + # Optionally override subnet/global settings for some hosts. + default_lease_time => 600, + max_lease_time => 900 } ``` diff --git a/manifests/host.pp b/manifests/host.pp index 9ceeed676..9e25686cf 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -3,10 +3,12 @@ define dhcp::host ( Stdlib::IP::Address $ip, Dhcp::Mac $mac, - String $ddns_hostname = $name, - Hash $options = {}, - String $comment = '', - Boolean $ignored = false, + String $ddns_hostname = $name, + Hash $options = {}, + String $comment = '', + Boolean $ignored = false, + Optional[Integer] $default_lease_time = undef, + Optional[Integer] $max_lease_time = undef, ) { $host = $name diff --git a/spec/defines/host_spec.rb b/spec/defines/host_spec.rb index ba2812b68..50efdba9e 100644 --- a/spec/defines/host_spec.rb +++ b/spec/defines/host_spec.rb @@ -62,6 +62,30 @@ end end + context 'when optional parameters defined' do + let(:params) do + default_params.merge( + 'default_lease_time' => 600, + 'max_lease_time' => 900 + ) + end + + it 'creates a host declaration with optional parameters' do + content = catalogue.resource('concat::fragment', "dhcp_host_#{title}").send(:parameters)[:content] + expected_lines = [ + "host #{title} {", + ' # test_comment', + " hardware ethernet #{params['mac']};", + " fixed-address #{params['ip']};", + " ddns-hostname \"#{title}\";", + ' default-lease-time 600;', + ' max-lease-time 900;', + '}' + ] + expect(content.split("\n")).to match_array(expected_lines) + end + end + context 'when ignored defined' do let(:params) do default_params.merge( diff --git a/templates/dhcpd.host.erb b/templates/dhcpd.host.erb index fca3e2be1..bd4b809b2 100644 --- a/templates/dhcpd.host.erb +++ b/templates/dhcpd.host.erb @@ -8,6 +8,12 @@ host <%= @host %> { <% if @ignored -%> ignore booting; <% end -%> +<% if @default_lease_time -%> + default-lease-time <%= @default_lease_time %>; +<% end -%> +<% if @max_lease_time -%> + max-lease-time <%= @max_lease_time %>; +<% end -%> <% if not @options.empty? -%> <% @options.keys.sort.each do |option| -%> option <%= option %> <%= @options[option] %>;