From eda301b7ba8f8827d1c9973ffaba0c1c7a029d98 Mon Sep 17 00:00:00 2001 From: Raphaƫl Pinson Date: Fri, 12 Apr 2013 12:29:45 +0200 Subject: Add spec for dhcp::subnet and improve template and definition --- manifests/subnet.pp | 57 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'manifests') diff --git a/manifests/subnet.pp b/manifests/subnet.pp index 18ffdc5..b9826da 100644 --- a/manifests/subnet.pp +++ b/manifests/subnet.pp @@ -27,16 +27,29 @@ # 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 +61,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 => $ensure, + false => 'absent', + } + 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', } } -- cgit v1.2.3