dhcp: Merge from parameterize branch
This commit is contained in:
parent
bd5ccf4211
commit
55c8b7bd5f
2 changed files with 48 additions and 75 deletions
|
@ -1,6 +1,6 @@
|
|||
# Install common parts of DHCP server
|
||||
#
|
||||
class dhcp::server::common {
|
||||
class dhcp::server::common($interface=undef) {
|
||||
|
||||
case $::operatingsystem {
|
||||
"centos","redhat": {
|
||||
|
@ -21,6 +21,13 @@ class dhcp::server::common {
|
|||
$confdir = "/etc"
|
||||
$package = "isc-dhcp-server"
|
||||
$service = "isc_dhcpd"
|
||||
|
||||
Service["dhcpd"] {
|
||||
flags => $interface ? {
|
||||
undef => "-q -user _isc-dhcp -group _isc-dhcp",
|
||||
default => "-q -user _isc-dhcp -group _isc-dhcp ${interface}",
|
||||
},
|
||||
}
|
||||
}
|
||||
"ubuntu": {
|
||||
if versioncmp($::operatingsystemrelease, "12.04") >= 0 {
|
||||
|
@ -57,7 +64,7 @@ class dhcp::server::common {
|
|||
|
||||
file { "/var/db/dhcpd.leases":
|
||||
ensure => present,
|
||||
mode => 0644,
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "wheel",
|
||||
before => Service["dhcpd"],
|
||||
|
@ -68,36 +75,25 @@ class dhcp::server::common {
|
|||
ensure => running,
|
||||
enable => true,
|
||||
name => $service,
|
||||
binary => $::operatingsystem ? {
|
||||
"openbsd" => "/usr/local/sbin/dhcpd",
|
||||
default => undef,
|
||||
},
|
||||
start => $::operatingsystem ? {
|
||||
"openbsd" => $dhcp_server_interface ? {
|
||||
"" => "/usr/local/sbin/dhcpd -q",
|
||||
default => "/usr/local/sbin/dhcpd -q ${dhcp_server_interface}",
|
||||
},
|
||||
default => undef,
|
||||
},
|
||||
require => Package["dhcp"],
|
||||
}
|
||||
|
||||
if $dhcp_server_interface {
|
||||
if $interface {
|
||||
case $::operatingsystem {
|
||||
"centos","redhat": {
|
||||
"fedora","centos","redhat": {
|
||||
file { "/etc/sysconfig/dhcpd":
|
||||
ensure => present,
|
||||
content => template("dhcp/dhcpd.sysconfig"),
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
content => template("dhcp/dhcpd.sysconfig"),
|
||||
require => Package["dhcp"],
|
||||
notify => Service["dhcpd"],
|
||||
}
|
||||
}
|
||||
"openbsd": {}
|
||||
default: {
|
||||
fail("Variable \${dhcp_server_interface} not supported in ${::operatinsystem}")
|
||||
fail("Parameter interface not supported in ${::operatinsystem}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,24 +103,30 @@ class dhcp::server::common {
|
|||
|
||||
# Install DHCP server with static config.
|
||||
#
|
||||
# === Global variables
|
||||
# === Parameters
|
||||
#
|
||||
# $dhcp_server_interface:
|
||||
# $interface:
|
||||
# Interface that DHCP server should listen. Defaults to all.
|
||||
#
|
||||
class dhcp::server inherits dhcp::server::common {
|
||||
class dhcp::server($interface=undef) {
|
||||
|
||||
class { "dhcp::server::common":
|
||||
interface => $interface,
|
||||
}
|
||||
|
||||
file { "dhcpd.conf":
|
||||
name => "${confdir}/dhcpd.conf",
|
||||
ensure => present,
|
||||
source => [ "puppet:///files/dhcp/dhcpd.conf.${::homename}",
|
||||
"puppet:///files/dhcp/dhcpd.conf", ],
|
||||
name => "${dhcp::server::common::confdir}/dhcpd.conf",
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => $::operatingsystem ? {
|
||||
"openbsd" => "wheel",
|
||||
default => "root",
|
||||
},
|
||||
source => [
|
||||
"puppet:///files/dhcp/dhcpd.conf.${::homename}",
|
||||
"puppet:///files/dhcp/dhcpd.conf",
|
||||
],
|
||||
notify => Service["dhcpd"],
|
||||
}
|
||||
|
||||
|
@ -133,38 +135,46 @@ class dhcp::server inherits dhcp::server::common {
|
|||
|
||||
# Install DHCP server and generate config from LDAP.
|
||||
#
|
||||
# === Global variables
|
||||
# === Parameters
|
||||
#
|
||||
# $dhcp_server_interface:
|
||||
# $interface:
|
||||
# Interface that DHCP server should listen. Defaults to all.
|
||||
#
|
||||
class dhcp::server::ldap inherits dhcp::server::common {
|
||||
class dhcp::server::ldap($interface=undef) {
|
||||
|
||||
include python
|
||||
include ldap::client
|
||||
class { "dhcp::server::common":
|
||||
interface => $interface,
|
||||
}
|
||||
|
||||
require python
|
||||
require ldap::client
|
||||
|
||||
file { "/usr/local/sbin/dhcpdump.py":
|
||||
ensure => present,
|
||||
source => "puppet:///modules/dhcp/dhcpdump.py",
|
||||
mode => "0755",
|
||||
owner => "root",
|
||||
group => $::operatingsystem ? {
|
||||
"openbsd" => "wheel",
|
||||
default => "root",
|
||||
},
|
||||
source => "puppet:///modules/dhcp/dhcpdump.py",
|
||||
}
|
||||
|
||||
$confdir = $dhcp::server::common::confdir
|
||||
|
||||
file { "dhcpd.conf.in":
|
||||
ensure => present,
|
||||
name => "${confdir}/dhcpd.conf.in",
|
||||
source => [ "puppet:///files/dhcp/dhcpd.conf.in.${hostname}",
|
||||
"puppet:///files/dhcp/dhcpd.conf.in", ],
|
||||
mode => "0644",
|
||||
owner => "root",
|
||||
group => $::operatingsystem ? {
|
||||
"openbsd" => "wheel",
|
||||
default => "root",
|
||||
},
|
||||
source => [
|
||||
"puppet:///files/dhcp/dhcpd.conf.in.${::hostname}",
|
||||
"puppet:///files/dhcp/dhcpd.conf.in",
|
||||
],
|
||||
require => Package["dhcp"],
|
||||
}
|
||||
|
||||
|
@ -172,45 +182,8 @@ class dhcp::server::ldap inherits dhcp::server::common {
|
|||
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
|
||||
command => "dhcpdump.py ${confdir}/dhcpd.conf.in* > ${confdir}/dhcpd.conf",
|
||||
unless => "dhcpdump.py ${confdir}/dhcpd.conf.in* | diff ${confdir}/dhcpd.conf -",
|
||||
require => [
|
||||
File["dhcpd.conf.in"],
|
||||
File["/usr/local/sbin/dhcpdump.py"],
|
||||
Class["python"],
|
||||
Class["ldap::client"],
|
||||
],
|
||||
require => File["dhcpd.conf.in", "/usr/local/sbin/dhcpdump.py"],
|
||||
notify => Service["dhcpd"],
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Configure DHCP relay
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# $name:
|
||||
# Relay name (can be anything).
|
||||
# $interface:
|
||||
# IP address for interface to listen.
|
||||
# $server_addr:
|
||||
# Address for DHCP server to relay requests.
|
||||
#
|
||||
# === Sample usage
|
||||
#
|
||||
# dhcp::relay { "relay0": interface => "em2", server_addr => "10.20.110.11" }
|
||||
#
|
||||
define dhcp::relay($interface, $server_addr) {
|
||||
|
||||
service { $name:
|
||||
ensure => running,
|
||||
provider => "base",
|
||||
hasrestart => false,
|
||||
hasstatus => false,
|
||||
pattern => "/usr/sbin/dhcrelay -i ${interface} ${server_addr}",
|
||||
start => $::operatingsystem ? {
|
||||
"openbsd" => "/usr/sbin/dhcrelay -i ${interface} ${server_addr}",
|
||||
default => undef,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<% if @operatingsystemrelease =~ /^6\./ -%>
|
||||
DHCPDARGS="-chroot ${statedir} -lf /dhcpd.leases -pf /dhcpd.pid <%= @dhcp_server_interface %>"
|
||||
DHCPDARGS="-chroot ${statedir} -lf /dhcpd.leases -pf /dhcpd.pid <%= @interface %>"
|
||||
pidfile="${statedir}/dhcpd.pid"
|
||||
<% else -%>
|
||||
DHCPDARGS="<%= @dhcp_server_interface %>"
|
||||
DHCPDARGS="<%= @interface %>"
|
||||
<% end -%>
|
||||
|
|
Loading…
Add table
Reference in a new issue