aboutsummaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
Diffstat (limited to 'manifests')
-rw-r--r--manifests/hosts.pp65
-rw-r--r--manifests/init.pp36
-rw-r--r--manifests/params.pp11
-rw-r--r--manifests/server.pp81
-rw-r--r--manifests/server/base.pp65
-rw-r--r--manifests/server/config.pp54
-rw-r--r--manifests/server/debian.pp21
-rw-r--r--manifests/server/packages.pp15
-rw-r--r--manifests/server/service.pp19
-rw-r--r--manifests/shared-network.pp25
-rw-r--r--manifests/shared_network.pp40
-rw-r--r--manifests/subnet.pp91
12 files changed, 314 insertions, 209 deletions
diff --git a/manifests/hosts.pp b/manifests/hosts.pp
index b159449..9c5d1b3 100644
--- a/manifests/hosts.pp
+++ b/manifests/hosts.pp
@@ -1,18 +1,17 @@
-# = Definition: dhcp::hosts
+# Definition: dhcp::hosts
#
-# Creates a dhcp configuration for given hosts
+# Creates a dhcp configuration for the given hosts
#
-# Arguments
-# $template: dhcp host template - default: 'dhcp/host.conf.erb'
-# $global_options: global options for the whole bunch of hosts.
-# you may override it per host, setting the host "options"
-# directly in the hash.
-# $subnet: targeted subnet
-# $hash_data: hash containing data - default form:
+# Parameters:
+# ['template'] - DHCP host template - default: 'dhcp/host.conf.erb'
+# ['global_options'] - An array of global options for the whole bunch of
+# hosts. You may override it per host, setting the
+# host "options" directly in the hash.
+# ['subnet'] - Targeted subnet
+# ['hash_data'] - Hash containing data - default form:
# {
# <host1> => {
-# options => false,
-# fixed_address => false,
+# options => ['opt1', 'opt2'],
# interfaces => {
# eth0 => 'mac-address',
# eth1 => 'mac-address',
@@ -22,8 +21,7 @@
# }
# },
# <host2> => {
-# options => false,
-# fixed_address => false,
+# fixed_address => 'foo.example.com',
# interfaces => {
# eth0 => 'mac-address',
# eth1 => 'mac-address',
@@ -35,16 +33,51 @@
# …,
# }
#
+# Sample usage:
+# ::dhcp::hosts { 'workstations':
+# subnet => '192.168.1.0',
+# 'hash_data' => {
+# 'host1' => {
+# 'interfaces' => {
+# 'eth0' => '00:11:22:33:44:55',
+# 'wlan0' => '00:aa:bb:44:55:ff',
+# },
+# },
+# 'host2' => {
+# 'interfaces' => {
+# 'eth1' => '00:11:af:33:44:55',
+# },
+# 'fixed_address' => 'foo.example.com',
+# 'options' => ['opt1'],
+# },
+# },
+# }
+#
+# Requires:
+# - puppetlabs/stdlib
+# - ripienaar/concat
+#
define dhcp::hosts (
$hash_data,
$subnet,
- $global_options = false,
- $template = 'dhcp/host.conf.erb',
+ $ensure = present,
+ $global_options = [],
+ $template = "${module_name}/host.conf.erb",
) {
- include dhcp::params
+ include ::dhcp::params
+
+ validate_string($ensure)
+ validate_re($ensure, ['present', 'absent'],
+ "\$ensure must be either 'present' or 'absent', got '${ensure}'")
+ validate_hash($hash_data)
+ validate_string($subnet)
+ validate_re($subnet, '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$')
+ validate_array($global_options)
+ validate_string($template)
concat::fragment {"dhcp.host.${name}":
+ ensure => $ensure,
target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf",
content => template($template),
notify => Service['dhcpd'],
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..9af496f
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,36 @@
+# Class: dhcp
+#
+# This class provides a simple way to install a DHCP server
+# It will install and configure the necessary packages.
+#
+# Parameters:
+# ['server'] - Whether to install the DHCP server
+# (default: true)
+# ['server_ddns_update'] - Set ddns_update on dhcp::server
+# ['server_authoritative'] - Set authoritative on dhcp::server
+# ['server_opts'] - Set opts for dhcp::server
+#
+# Actions:
+# - Deploys a DHCP server
+#
+# Sample usage:
+# include ::dhcp
+#
+# Requires:
+# - puppetlabs/stdlib
+# - ripienaar/concat
+#
+class dhcp (
+ $server = true,
+ $server_ddns_update = undef,
+ $server_authoritative = undef,
+ $server_opts = undef,
+) {
+ if $server {
+ class { '::dhcp::server':
+ ddns_update => $server_ddns_update,
+ authoritative => $server_authoritative,
+ opts => $server_opts,
+ }
+ }
+}
diff --git a/manifests/params.pp b/manifests/params.pp
index d2ba584..0938e4a 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,4 +1,4 @@
-# = Class: dhcp::params
+# Class: dhcp::params
#
# Do NOT include this class - it won't do anything.
# Set variables for names and paths
@@ -17,10 +17,17 @@ class dhcp::params {
lenny => 'dhcp3-server',
squeeze => 'isc-dhcp-server',
}
+
+ $service_pattern = $::lsbdistcodename? {
+ lenny => '/usr/sbin/dhcpd3',
+ squeeze => '/usr/sbin/dhcpd',
+ }
+
+ $server_template = "${module_name}/dhcpd.conf.debian.erb"
}
default: {
- fail "${name} is not available for ${::operatingsystem}/${::lsbdistcodename}"
+ fail "Unsupported OS ${::operatingsystem}/${::lsbdistcodename}"
}
}
diff --git a/manifests/server.pp b/manifests/server.pp
index 6bdf51f..a44cfe1 100644
--- a/manifests/server.pp
+++ b/manifests/server.pp
@@ -1,39 +1,44 @@
-/*
-
-= Class: dhcp::server
-Simple OS wrapper. Include this to install a dhcp server on your host.
-
-Requires:
- module "common": git://github.com/camptocamp/puppet-common.git
-
-facultative argument:
- *$dhcpd_ddns_update* : ddns-update-style option (default to none)
- *$dhcpd_authoritative* : set it if you want that your DHCP server is
- authoritative (default to no)
- *$dhcpd_opts* : any other DHCPD valid options
-
-Example:
-node "dhcp.toto.ltd" {
- $dhcpd_opts = ['domain-name "toto.ltd"', "domain-name-servers 192.168.21.1"]
- include dhcp::server
-
- dhcp::subnet {"10.27.20.0":
- ensure => present,
- broadcast => "10.27.20.255",
- other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'],
- }
-
- dhcp::host {"titi-eth0":
- ensure => present,
- mac => "0e:18:fa:fe:d9:00",
- subnet => "10.27.20.0",
- fixed_address => "10.27.10.52",
- }
-}
-*/
-
-class dhcp::server {
- case $::operatingsystem {
- Debian: { include dhcp::server::debian }
- }
+# Class: dhcp::server
+#
+# Installs and configures a DHCP server.
+#
+# Parameters:
+# ['ddns_update'] : ddns-update-style option (defaults to 'none')
+# ['authoritative'] : a boolean setting whether the DHCP server is
+# authoritative (defaults to false)
+# ['opts'] : an array of DHCPD valid options
+#
+# Sample usage:
+# node "dhcp.toto.ltd" {
+# class { 'dhcp::server':
+# opts => ['domain-name "toto.ltd"',
+# 'domain-name-servers 192.168.21.1'],
+# }
+#
+# dhcp::subnet {"10.27.20.0":
+# ensure => present,
+# broadcast => "10.27.20.255",
+# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'],
+# }
+#
+# dhcp::host {"titi-eth0":
+# ensure => present,
+# mac => "0e:18:fa:fe:d9:00",
+# subnet => "10.27.20.0",
+# fixed_address => "10.27.10.52",
+# }
+# }
+#
+# Requires:
+# - puppetlabs/stdlib
+# - ripienaar/concat
+#
+class dhcp::server (
+ $ddns_update = 'none',
+ $authoritative = false,
+ $opts = [],
+) {
+ class { '::dhcp::server::packages': } ->
+ class { '::dhcp::server::config': } ~>
+ class { '::dhcp::server::service': }
}
diff --git a/manifests/server/base.pp b/manifests/server/base.pp
deleted file mode 100644
index 4e7d645..0000000
--- a/manifests/server/base.pp
+++ /dev/null
@@ -1,65 +0,0 @@
-# = Class dhcp::server::base
-#
-# Do NOT include this class - it won't work at all.
-# Set variables for package name and so on.
-# This class should be inherited in dhcp::server::$operatingsystem.
-#
-class dhcp::server::base {
-
- include dhcp::params
- include concat::setup
-
- package {'dhcp-server':
- ensure => present,
- name => $dhcp::params::srv_dhcpd,
- }
-
- service {'dhcpd':
- ensure => running,
- name => $dhcp::params::srv_dhcpd,
- enable => true,
- require => Package['dhcp-server'],
- }
-
- concat {"${dhcp::params::config_dir}/dhcpd.conf":
- owner => root,
- group => root,
- mode => '0644',
- }
-
- concat::fragment {'00.dhcp.server.base':
- ensure => present,
- target => "${dhcp::params::config_dir}/dhcpd.conf",
- require => Package['dhcp-server'],
- notify => Service['dhcpd'],
- }
-
- file {"${dhcp::params::config_dir}/dhcpd.conf.d":
- ensure => directory,
- mode => '0700',
- recurse => true,
- purge => true,
- force => true,
- source => 'puppet:///modules/dhcp/empty'
- }
-
- file {"${dhcp::params::config_dir}/subnets":
- ensure => directory,
- recurse => true,
- purge => true,
- force => true,
- source => 'puppet:///modules/dhcp/empty',
- require => Package['dhcp-server'],
- notify => Service['dhcpd'],
- }
-
- file {"${dhcp::params::config_dir}/hosts.d":
- ensure => directory,
- recurse => true,
- purge => true,
- force => true,
- source => 'puppet:///modules/dhcp/empty',
- require => Package['dhcp-server'],
- }
-
-}
diff --git a/manifests/server/config.pp b/manifests/server/config.pp
new file mode 100644
index 0000000..0c1a74a
--- /dev/null
+++ b/manifests/server/config.pp
@@ -0,0 +1,54 @@
+# Class: dhcp::server::config
+#
+# Configure the DHCP server
+#
+class dhcp::server::config {
+ include ::dhcp::params
+ include ::concat::setup
+
+ validate_string($dhcp::params::config_dir)
+ validate_absolute_path($dhcp::params::config_dir)
+ validate_string($dhcp::params::server_template)
+ validate_re($dhcp::params::server_template, '^\S+$')
+
+ validate_string($dhcp::server::ddns_update)
+ validate_bool($dhcp::server::authoritative)
+ validate_array($dhcp::server::opts)
+
+ concat {"${dhcp::params::config_dir}/dhcpd.conf":
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+
+ concat::fragment {'00.dhcp.server.base':
+ ensure => present,
+ target => "${dhcp::params::config_dir}/dhcpd.conf",
+ content => template($dhcp::params::server_template),
+ }
+
+ file {"${dhcp::params::config_dir}/dhcpd.conf.d":
+ ensure => directory,
+ mode => '0700',
+ recurse => true,
+ purge => true,
+ force => true,
+ source => "puppet:///modules/${module_name}/empty"
+ }
+
+ file {"${dhcp::params::config_dir}/subnets":
+ ensure => directory,
+ recurse => true,
+ purge => true,
+ force => true,
+ source => "puppet:///modules/${module_name}/empty",
+ }
+
+ file {"${dhcp::params::config_dir}/hosts.d":
+ ensure => directory,
+ recurse => true,
+ purge => true,
+ force => true,
+ source => "puppet:///modules/${module_name}/empty",
+ }
+}
diff --git a/manifests/server/debian.pp b/manifests/server/debian.pp
deleted file mode 100644
index 5d23bbe..0000000
--- a/manifests/server/debian.pp
+++ /dev/null
@@ -1,21 +0,0 @@
-# = Class: dhcp::server::debian
-#
-# Installs a dhcp server on debian system.
-#
-# This class should not be included as is,
-# please include "dhcp::server" instead.
-#
-class dhcp::server::debian inherits dhcp::server::base {
-
- Concat::Fragment['00.dhcp.server.base'] {
- content => template('dhcp/dhcpd.conf.debian.erb'),
- }
-
- Service['dhcpd'] {
- pattern => $::lsbdistcodename ? {
- squeeze => '/usr/sbin/dhcpd',
- lenny => '/usr/sbin/dhcpd3',
- }
- }
-
-}
diff --git a/manifests/server/packages.pp b/manifests/server/packages.pp
new file mode 100644
index 0000000..b89ede3
--- /dev/null
+++ b/manifests/server/packages.pp
@@ -0,0 +1,15 @@
+# Class: dhcp::server::packages
+#
+# Install the DHCP server
+#
+class dhcp::server::packages {
+ include ::dhcp::params
+
+ validate_string($dhcp::params::srv_dhcpd)
+ validate_re($dhcp::params::srv_dhcpd, '^\S+$')
+
+ package {'dhcp-server':
+ ensure => present,
+ name => $dhcp::params::srv_dhcpd,
+ }
+}
diff --git a/manifests/server/service.pp b/manifests/server/service.pp
new file mode 100644
index 0000000..ef016c5
--- /dev/null
+++ b/manifests/server/service.pp
@@ -0,0 +1,19 @@
+# Class: dhcp::server::service
+#
+# Manage the DHCP server service
+#
+class dhcp::server::service {
+ include ::dhcp::params
+
+ validate_string($dhcp::params::srv_dhcpd)
+ validate_re($dhcp::params::srv_dhcpd, '^\S+$')
+ validate_string($dhcp::params::service_pattern)
+ validate_re($dhcp::params::service_pattern, '^\S+$')
+
+ service {'dhcpd':
+ ensure => running,
+ name => $dhcp::params::srv_dhcpd,
+ enable => true,
+ pattern => $dhcp::params::service_pattern,
+ }
+}
diff --git a/manifests/shared-network.pp b/manifests/shared-network.pp
deleted file mode 100644
index 9a02a5b..0000000
--- a/manifests/shared-network.pp
+++ /dev/null
@@ -1,25 +0,0 @@
-# == Definition: dhcp::shared-network
-# Creates a shared-network
-#
-# Arguments:
-# *$subnets* : subnet list to be included in the shared-network
-#
-# Warnings:
-# - subnets must exists
-# - subnets must have $is_shared set to true (default is false)
-#
-define dhcp::shared-network(
- $ensure = present,
- $subnets = []
-) {
-
- include dhcp::params
-
- concat::fragment {"shared-${name}":
- ensure => $ensure,
- target => "${dhcp::params::config_dir}/dhcpd.conf",
- content => template('dhcp/shared-network.erb'),
- require => Dhcp::Subnet[$subnets],
- }
-
-}
diff --git a/manifests/shared_network.pp b/manifests/shared_network.pp
new file mode 100644
index 0000000..766f432
--- /dev/null
+++ b/manifests/shared_network.pp
@@ -0,0 +1,40 @@
+# Definition: dhcp::shared-network
+#
+# Creates a shared-network
+#
+# Parameters:
+# ['subnets'] - An array of subnets to be included in the shared-network.
+#
+# Sample usage:
+# ::dhcp::shared_network { 'office':
+# subnets => ['192.168.1.0', '192.168.2.0'],
+# }
+#
+# Requires:
+# - puppetlabs/stdlib
+# - ripienaar/concat
+#
+# Warnings:
+# - subnets must exists
+# - subnets must have $is_shared set to true (default is false)
+#
+define dhcp::shared_network(
+ $ensure = present,
+ $subnets = [],
+) {
+
+ include ::dhcp::params
+
+ validate_string($ensure)
+ validate_re($ensure, ['present', 'absent'],
+ "\$ensure must be either 'present' or 'absent', got '${ensure}'")
+ validate_array($subnets)
+
+ concat::fragment {"dhcp-shared-${name}":
+ ensure => $ensure,
+ target => "${dhcp::params::config_dir}/dhcpd.conf",
+ content => template("${module_name}/shared-network.erb"),
+ require => Dhcp::Subnet[$subnets],
+ }
+
+}
diff --git a/manifests/subnet.pp b/manifests/subnet.pp
index 18ffdc5..e7c72dd 100644
--- a/manifests/subnet.pp
+++ b/manifests/subnet.pp
@@ -1,42 +1,53 @@
-# = Definition: dhcp::subnet
-# Creates a subnet
-#
-# Arguments:
-# *$broadcast* : subnet broadcast (mandatory)
-# *$netmask* : subnet netmask (if not set, takes eth0 netmask)
-# *$routers* : subnet routers (array) (if not set, takes eth0 IP)
-# *$subnet_mask* : netmask sent to dhcp guests (if not set, takes
-# $netmask, or netmask_eth0)
-# *$domain_name* : subnet domain name (if not set, takes server domain)
-# *$other_opts* : any other DHCPD option, as an array
-# *$is_shared* : whether it's part of a shared network or not. Default: false
+# Definition: dhcp::subnet
#
-# Example:
+# Creates a subnet
#
-# node "dhcp.domain.ltd" {
-# $dhcpd_domain_name = 'domain.ltd'
-# $dhcpd_dns_servers = '10.27.21.1, 10.26.21.1'
-# include dhcp
+# Parameters:
+# ['broadcast'] : subnet broadcast (mandatory)
+# ['netmask'] : subnet netmask
+# (default: $::netmask_eth0)
+# ['routers'] : An array of subnet routers
+# (default: $::netmask)
+# ['subnet_mask'] : netmask sent to dhcp guests
+# (default: the value of $netmask)
+# ['domain_name'] : subnet domain name
+# (default: $::domain)
+# ['other_opts'] : An array of additional DHCPD options
+# ['is_shared'] : whether it's part of a shared network or not
+# (default: false)
#
+# Sample usage:
# dhcp::subnet {"10.27.20.0":
# ensure => present,
# broadcast => "10.27.20.255",
# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'],
# }
-# }
#
define dhcp::subnet(
$broadcast,
- $ensure=present,
- $netmask=false,
- $routers=false,
- $subnet_mask=false,
- $domain_name=false,
- $other_opts=false,
- $is_shared=false
+ $ensure = present,
+ $netmask = undef,
+ $routers = [],
+ $subnet_mask = undef,
+ $domain_name = undef,
+ $other_opts = [],
+ $is_shared = false
) {
- include dhcp::params
+ include ::dhcp::params
+
+ $ip_re = '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$'
+
+ validate_string($ensure)
+ validate_re($ensure, ['present', 'absent'],
+ "\$ensure must be either 'present' or 'absent', got '${ensure}'")
+ validate_string($broadcast)
+ validate_re($broadcast, $ip_re)
+ validate_string($netmask)
+ validate_array($routers)
+ validate_string($subnet_mask)
+ validate_string($domain_name)
+ validate_bool($is_shared)
concat {"${dhcp::params::config_dir}/hosts.d/${name}.conf":
owner => root,
@@ -48,34 +59,30 @@ define dhcp::subnet(
ensure => $ensure,
owner => root,
group => root,
- content => template('dhcp/subnet.conf.erb'),
+ content => template("${module_name}/subnet.conf.erb"),
notify => Service['dhcpd'],
}
- if ! $is_shared {
- concat::fragment {"dhcp.${name}":
- ensure => $ensure,
- target => "${dhcp::params::config_dir}/dhcpd.conf",
- content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n",
- }
- } else {
- concat::fragment {"dhcp.${name}":
- ensure => absent,
- target => "${dhcp::params::config_dir}/dhcpd.conf",
- content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n",
- }
-
+ $ensure_shared = $is_shared ? {
+ true => 'absent',
+ false => $ensure,
+ }
+ concat::fragment {"dhcp.subnet.${name}":
+ ensure => $ensure_shared,
+ target => "${dhcp::params::config_dir}/dhcpd.conf",
+ content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n",
}
- concat::fragment {"subnet.${name}.hosts":
+ concat::fragment {"dhcp.subnet.${name}.hosts":
ensure => $ensure,
target => "${dhcp::params::config_dir}/dhcpd.conf",
content => "include \"${dhcp::params::config_dir}/hosts.d/${name}.conf\";\n",
}
- concat::fragment {"00.dhcp.${name}.base":
+ concat::fragment {"dhcp.subnet.${name}.base":
ensure => $ensure,
target => "${dhcp::params::config_dir}/hosts.d/${name}.conf",
content => "# File managed by puppet\n",
+ order => '00',
}
}