From 09472781f9882a2e7f2175bc83f5cd42bf721b33 Mon Sep 17 00:00:00 2001 From: Denver Mcanally Date: Tue, 28 Nov 2017 15:19:32 -0600 Subject: [PATCH] Fixing #62 - add support for dhcp6 --- README.md | 29 +++++++++++++++++ manifests/dhcp6.pp | 67 +++++++++++++++++++++++++++++++++++++++ manifests/host6.pp | 15 +++++++++ manifests/params.pp | 10 +++--- manifests/pool6.pp | 26 +++++++++++++++ templates/dhcpd6.conf.erb | 33 +++++++++++++++++++ templates/dhcpd6.host.erb | 4 +++ templates/dhcpd6.pool.erb | 52 ++++++++++++++++++++++++++++++ 8 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 manifests/dhcp6.pp create mode 100644 manifests/host6.pp create mode 100644 manifests/pool6.pp create mode 100644 templates/dhcpd6.conf.erb create mode 100644 templates/dhcpd6.host.erb create mode 100644 templates/dhcpd6.pool.erb diff --git a/README.md b/README.md index bae9204c..badcead5 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,15 @@ Define the server and the zones it will be responsible for. pxefilename => 'pxelinux.0', } +DHCPD6 can be deployed by defining the following class. Note, class dhcp is required. + + class { 'dhcp::dhcp6': + dnsdomain => [ + 'dc1.example.net', + ], + nameservers => ['3ffe:501:ffff:100:200:ff:fe00:3f3e'], + } + ### dhcp::pool Define the pool attributes @@ -63,6 +72,16 @@ For the support of static routes (RFC3442): { 'mask' => '0', 'gateway' => $gw } ], } +### dhcp::pool6 +An example for defining an ipv6 subnet: + + dhcp::pool6{ 'v6domain.example.net': + network => '3ffe:501:ffff::', + prefix => 64, + search_domains => ['domain.example.net'], + range => '3ffe:501:ffff::1fff 3ffe:501:ffff::ffff', + } + ### dhcp::host Create host reservations. @@ -72,6 +91,16 @@ Create host reservations. 'server3': mac => "00:50:56:00:00:03", ip => "10.0.1.53"; } +### dhcp::host6 +Create ipv6 host reservation + + dhcp::host6 { + 'server1': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::51"; + 'server2': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::52"; + 'server3': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::53"; + } + + ## Contributors Original authors: diff --git a/manifests/dhcp6.pp b/manifests/dhcp6.pp new file mode 100644 index 00000000..60d23b2d --- /dev/null +++ b/manifests/dhcp6.pp @@ -0,0 +1,67 @@ +# class dhcp::dhcp6 +class dhcp::dhcp6 ( + Array[String] $dnsdomain = $dhcp::params::dnsdomain, + Array[String] $nameservers = ['2001:4860:4860::8888', '2001:4860:4860::8844'], + Integer[0] $default_lease_time6 = 2592000, + Integer[0] $default_preferred_lifetime6 = 604800, + Integer[0] $default_renewal_time6 = 3600, + Integer[0] $default_rebinding_time6 = 7200, + Integer[0] $default_info_refresh_time6 = 21600, + Boolean $leasequery6 = true, + Boolean $rapid_commit6 = false, + Integer[0] $default_preference6 = 10, + Stdlib::Absolutepath $dhcp_dir = $dhcp::params::dhcp_dir, + Stdlib::Absolutepath $default_leasefile_path6 = $dhcp::params::default_leasefile_path6, + String $packagename = $dhcp::params::packagename, + String $servicename6 = $dhcp::params::servicename6, + Variant[Array[String], Optional[String]] $options = undef, + String $dhcp_root_group = $dhcp::params::root_group, + Hash[String, Hash] $pools6 = {}, + Hash[String, Hash] $hosts6 = {}, + Variant[Array[String], Optional[String]] $includes = undef, +) inherits dhcp::params { + + concat { "${dhcp_dir}/dhcpd6.conf": + owner => 'root', + group => $dhcp_root_group, + mode => '0644', + require => Package[$packagename], + notify => Service[$servicename6], + } + + concat::fragment { 'dhcp6.conf+01_main.dhcp': + target => "${dhcp_dir}/dhcpd6.conf", + content => template('dhcp/dhcpd6.conf.erb'), + order => '01', + } + + if $includes { + concat::fragment { 'dhcp6.conf+20_includes': + target => "${dhcp_dir}/dhcpd6.conf", + content => template('dhcp/dhcpd6.conf.includes.erb'), + order => '20', + } + } + + concat { "${dhcp_dir}/dhcpd6.hosts": + owner => 'root', + group => $dhcp_root_group, + mode => '0644', + require => Package[$packagename], + notify => Service[$servicename6], + } + + concat::fragment { 'dhcp6.hosts+01_main.hosts': + target => "${dhcp_dir}/dhcpd6.hosts", + content => "# static DHCP hosts\n", + order => '01', + } + + create_resources('dhcp::pool6', $pools6) + create_resources('dhcp::host6', $hosts6) + + service { $servicename6: + ensure => running, + enable => true, + } +} diff --git a/manifests/host6.pp b/manifests/host6.pp new file mode 100644 index 00000000..fea8325b --- /dev/null +++ b/manifests/host6.pp @@ -0,0 +1,15 @@ +#class dhcp::host6 +define dhcp::host6 ( + String $ip, + Dhcp::Macaddress $mac, + Optional[String] $comment=undef, +) { + + $host = $name + + concat::fragment { "dhcp.hosts+10_${name}.hosts": + target => "${::dhcp::dhcp_dir}/dhcpd6.hosts", + content => template('dhcp/dhcpd6.host.erb'), + order => "10-${name}", + } +} diff --git a/manifests/params.pp b/manifests/params.pp index e1c25a8a..cc7a695c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -33,10 +33,12 @@ } 'RedHat': { - $dhcp_dir = '/etc/dhcp' - $packagename = 'dhcp' - $servicename = 'dhcpd' - $root_group = 'root' + $dhcp_dir = '/etc/dhcp' + $default_leasefile_path6 = '/var/lib/dhcpd/dhcpd6.leases' + $packagename = 'dhcp' + $servicename = 'dhcpd' + $servicename6 = 'dhcpd6' + $root_group = 'root' if $::operatingsystemrelease =~ /^[0-6]\./ { $bootfiles = { '00:07' => 'grub/grubx64.efi', diff --git a/manifests/pool6.pp b/manifests/pool6.pp new file mode 100644 index 00000000..629a4467 --- /dev/null +++ b/manifests/pool6.pp @@ -0,0 +1,26 @@ +# class dhcp::pool6 +define dhcp::pool6 ( + String $network, + Integer[0] $prefix, + Variant[Array[String], Optional[String]] $pool_parameters = undef, + Variant[Array[Dhcp::Range], String, Optional[Dhcp::Range], Enum[''], Boolean] $range = undef, + Optional[String] $failover = 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, + Variant[Array[String], Optional[String]] $search_domains = undef, + Optional[String] $raw_append = undef, + Optional[String] $raw_prepend = undef, +) { + + concat::fragment { "dhcp6.conf+70_${name}.dhcp": + target => "${::dhcp::dhcp_dir}/dhcpd6.conf", + content => template('dhcp/dhcpd6.pool.erb'), + order => "70-${name}", + } + +} diff --git a/templates/dhcpd6.conf.erb b/templates/dhcpd6.conf.erb new file mode 100644 index 00000000..62002bdd --- /dev/null +++ b/templates/dhcpd6.conf.erb @@ -0,0 +1,33 @@ +# dhcpd6.conf + +default-lease-time <%= @default_lease_time6 %>; +preferred-lifetime <%= @default_preferred_lifetime6 %>; +option dhcp-renewal-time <%= @default_renewal_time6 %>; +option dhcp-rebinding-time <%= @default_rebinding_time6 %>; +option dhcp6.info-refresh-time <%= @default_info_refresh_time6 %>; + +<% if @leasequery6 -%> +allow leasequery; +<% end -%> + +<% if @default_preference6 -%> +option dhcp6.preference 255; +<% end -%> + +<% if @rapid_commit6 -%> +option dhcp6.rapid-commit; +<% end -%> + +<% if @nameservers and @nameservers.is_a? Array -%> +option dhcp6.name-servers <%= @nameservers.sort.join(', ') %>; +<% elsif @nameservers -%> +option dhcp6.name-servers <%= @nameservers %>; +<% end -%> +<% if @search_domains and @search_domains.is_a? Array -%> +option dhcp6.domain-search "<%= @search_domains.sort.join('", "') %>"; +<% elsif @search_domains -%> +option dhcp6.domain-search "<%= @search_domains.split(/[, ]+/).join('", "') %>"; +<% end -%> + +# The path of the lease file +dhcpv6-lease-file-name "<%= @default_leasefile_path6 %>"; diff --git a/templates/dhcpd6.host.erb b/templates/dhcpd6.host.erb new file mode 100644 index 00000000..8b073d74 --- /dev/null +++ b/templates/dhcpd6.host.erb @@ -0,0 +1,4 @@ +host <%= @host %> { + hardware ethernet <%= @mac %>; + fixed-address6 <%= @ip %>; +} diff --git a/templates/dhcpd6.pool.erb b/templates/dhcpd6.pool.erb new file mode 100644 index 00000000..dd1a488d --- /dev/null +++ b/templates/dhcpd6.pool.erb @@ -0,0 +1,52 @@ +# <%= @name %> +subnet6 <%= @network %>/<%= @prefix %> { +<% if @raw_prepend -%> + <%= @raw_prepend %> +<% end -%> +<% if (@range && @range.is_a?(String) && !@range.strip.empty?) || (@range && @range.is_a?(Array)) -%> +<% if @pool_parameters.is_a? Array -%> +<% @pool_parameters.each do |param| -%> + <%= param %>; +<% end -%> +<% elsif @pool_parameters && !@pool_parameters.strip.empty? -%> + <%= @pool_parameters %>; +<% end -%> +<% if @range and @range.is_a? Array -%> +<% @range.each do |rng| -%> + range6 <%= rng %>; +<% end -%> +<% elsif @range && !@range.strip.empty? -%> + range6 <%= @range %>; +<% end -%> +<% end -%> +<% if @domain_name && !@domain_name.strip.empty? -%> + option dhcp6.domain-name "<%= @domain_name %>"; +<% end -%> +<% if @options.is_a? Array -%> +<% @options.each do |opt| -%> + option <%= opt %>; +<% end -%> +<% elsif @options && !@options.strip.empty? -%> + option <%= @options %>; +<% end -%> +<% if @parameters.is_a? Array -%> +<% @parameters.each do |param| -%> + <%= param %>; +<% end -%> +<% elsif @parameters && !@parameters.strip.empty? -%> + <%= @parameters %>; +<% end -%> +<% if @nameservers and @nameservers.is_a? Array -%> + option dhcp6.name-servers <%= @nameservers.sort.join(', ') %>; +<% elsif @nameservers -%> + option dhcp6.name-servers <%= @nameservers %>; +<% end -%> +<% if @search_domains and @search_domains.is_a? Array -%> + option dhcp6.domain-search "<%= @search_domains.sort.join('", "') %>"; +<% elsif @search_domains -%> + option dhcp6.domain-search "<%= @search_domains.split(/[, ]+/).join('", "') %>"; +<% end -%> +<% if @raw_append -%> + <%= @raw_append %> +<% end -%> +}