Showing with 268 additions and 27 deletions.
  1. +1 −3 .fixtures.yml
  2. +13 −4 CHANGELOG.md
  3. +3 −0 Gemfile
  4. +30 −0 README.md
  5. +8 −0 manifests/host.pp
  6. +2 −0 manifests/init.pp
  7. +20 −5 manifests/pool.pp
  8. +70 −0 manifests/subnet.pp
  9. +6 −4 metadata.json
  10. +34 −0 spec/defines/host_spec.rb
  11. +43 −0 spec/type_aliases/dhcppool_spec.rb
  12. +6 −0 templates/dhcpd.host.erb
  13. +13 −11 templates/{dhcpd.pool.erb → dhcpd.subnet.erb}
  14. +19 −0 types/dhcppool.pp
4 changes: 1 addition & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
fixtures:
repositories:
augeas_core:
repo: 'https://github.com/puppetlabs/puppetlabs-augeas_core'
puppet_version: '>= 6.0.0'
augeas_core: 'https://github.com/puppetlabs/puppetlabs-augeas_core'
concat: 'https://github.com/puppetlabs/puppetlabs-concat'
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
systemd: 'https://github.com/voxpupuli/puppet-systemd'
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [8.1.0](https://github.com/theforeman/puppet-dhcp/tree/8.1.0) (2022-02-03)

[Full Changelog](https://github.com/theforeman/puppet-dhcp/compare/8.0.0...8.1.0)

**Implemented enhancements:**

- Add Debian 11 and Ubuntu 20.04 support [\#208](https://github.com/theforeman/puppet-dhcp/pull/208) ([ekohl](https://github.com/ekohl))
- add support for raw configuration for host declarations. [\#206](https://github.com/theforeman/puppet-dhcp/pull/206) ([UiP9AV6Y](https://github.com/UiP9AV6Y))
- puppetlabs/stdlib: Allow 8.x [\#204](https://github.com/theforeman/puppet-dhcp/pull/204) ([bastelfreak](https://github.com/bastelfreak))
- Add support for multiple pools in a subnet [\#164](https://github.com/theforeman/puppet-dhcp/pull/164) ([peterverraedt](https://github.com/peterverraedt))

## [8.0.0](https://github.com/theforeman/puppet-dhcp/tree/8.0.0) (2021-10-29)

[Full Changelog](https://github.com/theforeman/puppet-dhcp/compare/7.0.0...8.0.0)
Expand Down Expand Up @@ -62,6 +73,7 @@
**Breaking changes:**

- Use modern facts [\#175](https://github.com/theforeman/puppet-dhcp/issues/175)
- Default nameservers to an empty array [\#171](https://github.com/theforeman/puppet-dhcp/pull/171) ([jhoblitt](https://github.com/jhoblitt))

**Implemented enhancements:**

Expand Down Expand Up @@ -92,10 +104,6 @@

[Full Changelog](https://github.com/theforeman/puppet-dhcp/compare/5.0.0...5.0.1)

**Breaking changes:**

- Default nameservers to an empty array [\#171](https://github.com/theforeman/puppet-dhcp/pull/171) ([jhoblitt](https://github.com/jhoblitt))

**Merged pull requests:**

- allow newer puppetlabs-concat version [\#157](https://github.com/theforeman/puppet-dhcp/pull/157) ([mmoll](https://github.com/mmoll))
Expand All @@ -108,6 +116,7 @@
**Breaking changes:**

- drop Puppet 4 [\#152](https://github.com/theforeman/puppet-dhcp/pull/152) ([mmoll](https://github.com/mmoll))
- drop EOL OSes [\#151](https://github.com/theforeman/puppet-dhcp/pull/151) ([mmoll](https://github.com/mmoll))

**Implemented enhancements:**

Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ gem 'puppet-blacksmith', '>= 6.0.0', {"groups"=>["development"]}
gem 'voxpupuli-acceptance', '~> 1.0', {"groups"=>["system_tests"]}
gem 'puppetlabs_spec_helper', {"groups"=>["system_tests"]}

# Pin rdoc to prevent updating bundled psych (https://github.com/ruby/rdoc/commit/ebe185c8775b2afe844eb3da6fa78adaa79e29a4)
gem 'rdoc', '< 6.4'

# vim:ft=ruby
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Installs and manages a DHCP server.

## Features
* Multiple subnet support
* Support for multiple pools within a subnet
* Host reservations
* Secure dynamic DNS updates when combined with Bind
* Failover support
Expand All @@ -35,6 +36,8 @@ Define the server and the zones it will be responsible for.
}

### dhcp::pool
To create a subnet with a single pool, use dhcp::pool.

Define the pool attributes

dhcp::pool{ 'ops.dc1.example.net':
Expand Down Expand Up @@ -66,6 +69,33 @@ For the support of static routes (RFC3442):
{ 'mask' => '0', 'gateway' => $gw } ],
}

### dhcp::subnet
To create a subnet with multiple pools, use dhcp::subnet.

```puppet
dhcp::subnet{ 'ops.dc1.example.net':
network => '10.0.1.0',
mask => '255.255.255.0',
pools => [
{
range => '10.0.1.101 10.0.1.110',
parameters => [
'allow members of "group1"',
'next-server 10.1.1.1',
],
},
{
range => '10.0.1.111 10.0.1.120',
parameters => [
'allow members of "group2"',
'next-server 10.1.1.2',
],
},
],
gateway => '10.0.1.1',
}
```

### dhcp::host
Create host reservations.

Expand Down
8 changes: 8 additions & 0 deletions manifests/host.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
#
# @param comment
# An optional comment for the host
#
# @param raw_append
# Host configuration to append as-is
#
# @param raw_prepend
# Host configuration to prepend as-is
define dhcp::host (
String $ip,
Dhcp::Macaddress $mac,
Optional[String] $comment=undef,
Optional[String] $raw_append = undef,
Optional[String] $raw_prepend = undef,
) {

$host = $name
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Optional[String] $ddns_rev_domainname = undef,
Enum['none', 'interim', 'standard'] $ddns_update_style = 'interim',
Optional[Boolean] $client_updates = undef,
Hash[String, Hash] $subnets = {},
Hash[String, Hash] $pools = {},
Hash[String, Hash] $hosts = {},
Variant[Array[String], Optional[String]] $includes = undef,
Expand Down Expand Up @@ -154,6 +155,7 @@
order => '01',
}

create_resources('dhcp::subnet', $subnets)
create_resources('dhcp::pool', $pools)
create_resources('dhcp::host', $hosts)

Expand Down
25 changes: 20 additions & 5 deletions manifests/pool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@
Optional[String] $raw_prepend = undef,
) {

concat::fragment { "dhcp.conf+70_${name}.dhcp":
target => "${dhcp::dhcp_dir}/dhcpd.conf",
content => template('dhcp/dhcpd.pool.erb'),
order => "70-${name}",
dhcp::subnet { $name:
network => $network,
mask => $mask,
pools => [{
range => $range,
failover => $failover,
parameters => $pool_parameters,
}],
gateway => $gateway,
options => $options,
parameters => $parameters,
mtu => $mtu,
nameservers => $nameservers,
pxeserver => $pxeserver,
pxefilename => $pxefilename,
domain_name => $domain_name,
static_routes => $static_routes,
search_domains => $search_domains,
raw_append => $raw_append,
raw_prepend => $raw_prepend,
}

}
70 changes: 70 additions & 0 deletions manifests/subnet.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# @summary
# Define a DHCP subnet
# @param network
# The network range (without the mask) from where IP's will be served
# @param mask
# The subnet mask for our network
# @param pools
# Specify a pool of addresses that will be treated differently than another pool of addresses,
# even on the same network segment or subnet.
# @param gateway
# This option specifies a list of comma-separated IP addresses for routers on the client's subnet.
# Routers should be listed in order of preference.
# @param options
# Custom DHCP option statements
# DHCP option statements always start with the option keyword, followed by an option name, followed by option
# data. The option names and data formats are described below. It is not necessary to exhaustively specify all
# DHCP options - only those options which are needed by clients
# @param parameters
# Custom DHCP parameters
# Each element is added as a separate line
# @param mtu
# This option specifies the MTU to use on this interface. The minimum legal value for the MTU is 68.
# @param nameservers
# Specifies a list of Domain Name System (STD 13, RFC 1035) name servers available to the client.
# Servers should be listed in order of preference.
# @param pxeserver
# This is used to specify the host address of the server from which the initial boot file
# (specified in the filename statement) is to be loaded. Server-name should be a numeric IP address or a
# domain name. If no next-server statement applies to a given client, the address 0.0.0.0 is used.
# @param pxefilename
# This can be used to specify the name of the initial boot file which is to be loaded by a
# client. The filename should be a filename recognizable to whatever file transfer protocol the client can be
# expected to use to load the file.
# @param domain_name
# This option specifies the domain name that client should use when resolving hostnames via the Domain Name
# System.
# @param static_routes
# This option specifies a list of static routes that the client should install in its routing cache. If multiple
# routes to the same destination are specified, they are listed in descending order of priority.
# @param search_domains
# Specifies a ´search list´ of Domain Names to be used by the client to locate not-fully-qualified domain
# names. The difference between this option and historic use of the domain-name option
# for the same ends is that this option is encoded in RFC1035 compressed labels on the wire. For example:
# @param raw_append
# Partial that is appended to the dhcpd.conf (before the final `}`)
# @param raw_prepend
# Partial that is prepended to the dhcpd.conf (after the first `{`)
define dhcp::subnet (
Stdlib::IP::Address::Nosubnet $network,
Stdlib::IP::Address::Nosubnet $mask,
Array[Dhcp::DhcpPool] $pools,
Optional[String] $gateway = undef,
Variant[Array[String], Optional[String]] $options = undef,
Variant[Array[String], Optional[String]] $parameters = undef,
Optional[Integer[0]] $mtu = undef,
Variant[Array[String], Optional[String]] $nameservers = undef,
Optional[String] $pxeserver = undef,
Optional[String] $pxefilename = undef,
Optional[String] $domain_name = undef,
Optional[Array[Dhcp::StaticRoute]] $static_routes = undef,
Variant[Array[String], Optional[String]] $search_domains = undef,
Optional[String] $raw_append = undef,
Optional[String] $raw_prepend = undef,
) {
concat::fragment { "dhcp.conf+70_${name}.dhcp":
target => "${dhcp::dhcp_dir}/dhcpd.conf",
content => template('dhcp/dhcpd.subnet.erb'),
order => "70-${name}",
}
}
10 changes: 6 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "theforeman-dhcp",
"version": "8.0.0",
"version": "8.1.0",
"author": "theforeman",
"summary": "Manage the ISC DHCP daemon",
"license": "Apache-2.0",
Expand All @@ -25,7 +25,7 @@
},
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.18.0 < 8.0.0"
"version_requirement": ">= 4.18.0 < 9.0.0"
}
],
"requirements": [
Expand Down Expand Up @@ -66,14 +66,16 @@
"operatingsystem": "Debian",
"operatingsystemrelease": [
"9",
"10"
"10",
"11"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"16.04",
"18.04"
"18.04",
"20.04"
]
},
{
Expand Down
34 changes: 34 additions & 0 deletions spec/defines/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,40 @@

it_behaves_like "a concat template"
end

describe 'raw_prepend parameter' do
let(:params) { super().merge(raw_prepend: 'fixed-address6 FE80:0000:0000:0000:903A:1C1A:E802:11E4;') }

let(:expected_content) do
<<~CONTENT
host myhost {
fixed-address6 FE80:0000:0000:0000:903A:1C1A:E802:11E4;
hardware ethernet 01:02:03:04:05:06;
fixed-address 10.0.0.100;
ddns-hostname "myhost";
}
CONTENT
end

it_behaves_like "a concat template"
end

describe 'raw_append parameter' do
let(:params) { super().merge(raw_append: 'dhcp-client-identifier "spec";') }

let(:expected_content) do
<<~CONTENT
host myhost {
hardware ethernet 01:02:03:04:05:06;
fixed-address 10.0.0.100;
ddns-hostname "myhost";
dhcp-client-identifier "spec";
}
CONTENT
end

it_behaves_like "a concat template"
end
end
end
end
43 changes: 43 additions & 0 deletions spec/type_aliases/dhcppool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'spec_helper'

describe 'Dhcp::DhcpPool' do
it do
is_expected.to allow_values(
{
'range' => '10.0.0.100 10.0.0.200',
},
{
'range' => true,
},
{
'range' => [
'10.0.0.100 10.0.0.200',
'10.1.0.100 10.1.0.200',
],
'failover' => 'dhcp-failover',
'parameters' => 'omapi-port 7911',
},
{
'range' => '',
'parameters' => [
'omapi-key primaryhost',
'omapi-port 7911',
],
},
)
end

describe 'invalid value handling' do
[
nil,
{
'range' => 5,
},
{
'failover' => true,
},
].each do |value|
it { is_expected.not_to allow_value(value) }
end
end
end
6 changes: 6 additions & 0 deletions templates/dhcpd.host.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
# <%= @comment %>
<% end -%>
host <%= @host %> {
<% if @raw_prepend -%>
<%= @raw_prepend %>
<% end -%>
hardware ethernet <%= @mac %>;
fixed-address <%= @ip %>;
ddns-hostname "<%= @name %>";
<% if @raw_append -%>
<%= @raw_append %>
<% end -%>
}
Loading