From 745b2537e79eca59f8e9f2f15230482fcdf140aa Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 11:54:50 +0200 Subject: Refactor module * Use a top dhcp class with a $server boolean param * Refactor the dhcp::class to use packages/config/service classes * Don't use inheritance, put everything in dhcp::params --- manifests/server/packages.pp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 manifests/server/packages.pp (limited to 'manifests/server/packages.pp') diff --git a/manifests/server/packages.pp b/manifests/server/packages.pp new file mode 100644 index 0000000..34751e8 --- /dev/null +++ b/manifests/server/packages.pp @@ -0,0 +1,8 @@ +class dhcp::server::packages { + include ::dhcp::params + + package {'dhcp-server': + ensure => present, + name => $dhcp::params::srv_dhcpd, + } +} -- cgit v1.2.3 From 87096a875d4bee517e0c8c807218394a2024bd46 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 12:21:01 +0200 Subject: Add variable validations --- manifests/params.pp | 4 ++-- manifests/server/config.pp | 13 ++++++++++--- manifests/server/packages.pp | 7 +++++++ manifests/server/service.pp | 9 +++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) (limited to 'manifests/server/packages.pp') diff --git a/manifests/params.pp b/manifests/params.pp index 20fbcd2..925f3f5 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 @@ -23,7 +23,7 @@ class dhcp::params { squeeze => '/usr/sbin/dhcpd', } - $base_template = 'dhcp/dhcpd.conf.debian.erb' + $server_template = "${module_name}/dhcpd.conf.debian.erb" } default: { diff --git a/manifests/server/config.pp b/manifests/server/config.pp index c37d044..4898a60 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -1,7 +1,16 @@ +# 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+$') + concat {"${dhcp::params::config_dir}/dhcpd.conf": owner => root, group => root, @@ -11,7 +20,7 @@ class dhcp::server::config { concat::fragment {'00.dhcp.server.base': ensure => present, target => "${dhcp::params::config_dir}/dhcpd.conf", - content => template($dhcp::params::base_template), + content => template($dhcp::params::server_template), } file {"${dhcp::params::config_dir}/dhcpd.conf.d": @@ -29,8 +38,6 @@ class dhcp::server::config { purge => true, force => true, source => "puppet:///modules/${module_name}/empty", - require => Package['dhcp-server'], - notify => Service['dhcpd'], } file {"${dhcp::params::config_dir}/hosts.d": diff --git a/manifests/server/packages.pp b/manifests/server/packages.pp index 34751e8..b89ede3 100644 --- a/manifests/server/packages.pp +++ b/manifests/server/packages.pp @@ -1,6 +1,13 @@ +# 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 index d531a7d..ef016c5 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -1,6 +1,15 @@ +# 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, -- cgit v1.2.3