dhcp: Merge from parameterize branch

This commit is contained in:
Ossi Salmi 2016-04-18 15:15:31 +03:00
parent bd5ccf4211
commit 55c8b7bd5f
2 changed files with 48 additions and 75 deletions

View file

@ -1,6 +1,6 @@
# Install common parts of DHCP server # Install common parts of DHCP server
# #
class dhcp::server::common { class dhcp::server::common($interface=undef) {
case $::operatingsystem { case $::operatingsystem {
"centos","redhat": { "centos","redhat": {
@ -21,6 +21,13 @@ class dhcp::server::common {
$confdir = "/etc" $confdir = "/etc"
$package = "isc-dhcp-server" $package = "isc-dhcp-server"
$service = "isc_dhcpd" $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": { "ubuntu": {
if versioncmp($::operatingsystemrelease, "12.04") >= 0 { if versioncmp($::operatingsystemrelease, "12.04") >= 0 {
@ -57,7 +64,7 @@ class dhcp::server::common {
file { "/var/db/dhcpd.leases": file { "/var/db/dhcpd.leases":
ensure => present, ensure => present,
mode => 0644, mode => "0644",
owner => "root", owner => "root",
group => "wheel", group => "wheel",
before => Service["dhcpd"], before => Service["dhcpd"],
@ -68,36 +75,25 @@ class dhcp::server::common {
ensure => running, ensure => running,
enable => true, enable => true,
name => $service, 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"], require => Package["dhcp"],
} }
if $dhcp_server_interface { if $interface {
case $::operatingsystem { case $::operatingsystem {
"centos","redhat": { "fedora","centos","redhat": {
file { "/etc/sysconfig/dhcpd": file { "/etc/sysconfig/dhcpd":
ensure => present, ensure => present,
content => template("dhcp/dhcpd.sysconfig"),
mode => "0644", mode => "0644",
owner => "root", owner => "root",
group => "root", group => "root",
content => template("dhcp/dhcpd.sysconfig"),
require => Package["dhcp"], require => Package["dhcp"],
notify => Service["dhcpd"], notify => Service["dhcpd"],
} }
} }
"openbsd": {} "openbsd": {}
default: { 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. # Install DHCP server with static config.
# #
# === Global variables # === Parameters
# #
# $dhcp_server_interface: # $interface:
# Interface that DHCP server should listen. Defaults to all. # 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": file { "dhcpd.conf":
name => "${confdir}/dhcpd.conf",
ensure => present, ensure => present,
source => [ "puppet:///files/dhcp/dhcpd.conf.${::homename}", name => "${dhcp::server::common::confdir}/dhcpd.conf",
"puppet:///files/dhcp/dhcpd.conf", ],
mode => "0644", mode => "0644",
owner => "root", owner => "root",
group => $::operatingsystem ? { group => $::operatingsystem ? {
"openbsd" => "wheel", "openbsd" => "wheel",
default => "root", default => "root",
}, },
source => [
"puppet:///files/dhcp/dhcpd.conf.${::homename}",
"puppet:///files/dhcp/dhcpd.conf",
],
notify => Service["dhcpd"], notify => Service["dhcpd"],
} }
@ -133,38 +135,46 @@ class dhcp::server inherits dhcp::server::common {
# Install DHCP server and generate config from LDAP. # Install DHCP server and generate config from LDAP.
# #
# === Global variables # === Parameters
# #
# $dhcp_server_interface: # $interface:
# Interface that DHCP server should listen. Defaults to all. # 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 class { "dhcp::server::common":
include ldap::client interface => $interface,
}
require python
require ldap::client
file { "/usr/local/sbin/dhcpdump.py": file { "/usr/local/sbin/dhcpdump.py":
ensure => present, ensure => present,
source => "puppet:///modules/dhcp/dhcpdump.py",
mode => "0755", mode => "0755",
owner => "root", owner => "root",
group => $::operatingsystem ? { group => $::operatingsystem ? {
"openbsd" => "wheel", "openbsd" => "wheel",
default => "root", default => "root",
}, },
source => "puppet:///modules/dhcp/dhcpdump.py",
} }
$confdir = $dhcp::server::common::confdir
file { "dhcpd.conf.in": file { "dhcpd.conf.in":
ensure => present, ensure => present,
name => "${confdir}/dhcpd.conf.in", name => "${confdir}/dhcpd.conf.in",
source => [ "puppet:///files/dhcp/dhcpd.conf.in.${hostname}",
"puppet:///files/dhcp/dhcpd.conf.in", ],
mode => "0644", mode => "0644",
owner => "root", owner => "root",
group => $::operatingsystem ? { group => $::operatingsystem ? {
"openbsd" => "wheel", "openbsd" => "wheel",
default => "root", default => "root",
}, },
source => [
"puppet:///files/dhcp/dhcpd.conf.in.${::hostname}",
"puppet:///files/dhcp/dhcpd.conf.in",
],
require => Package["dhcp"], 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", path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
command => "dhcpdump.py ${confdir}/dhcpd.conf.in* > ${confdir}/dhcpd.conf", command => "dhcpdump.py ${confdir}/dhcpd.conf.in* > ${confdir}/dhcpd.conf",
unless => "dhcpdump.py ${confdir}/dhcpd.conf.in* | diff ${confdir}/dhcpd.conf -", unless => "dhcpdump.py ${confdir}/dhcpd.conf.in* | diff ${confdir}/dhcpd.conf -",
require => [ require => File["dhcpd.conf.in", "/usr/local/sbin/dhcpdump.py"],
File["dhcpd.conf.in"],
File["/usr/local/sbin/dhcpdump.py"],
Class["python"],
Class["ldap::client"],
],
notify => Service["dhcpd"], 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,
}
}
}

View file

@ -1,6 +1,6 @@
<% if @operatingsystemrelease =~ /^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" pidfile="${statedir}/dhcpd.pid"
<% else -%> <% else -%>
DHCPDARGS="<%= @dhcp_server_interface %>" DHCPDARGS="<%= @interface %>"
<% end -%> <% end -%>