diff options
author | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-04-14 23:50:03 -0700 |
---|---|---|
committer | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-04-14 23:50:03 -0700 |
commit | 93895f1f039956ec9d02df511aaeaed885ae34bf (patch) | |
tree | 704909c98dc11bb9206b2c67f3f8557418507a21 /manifests/hosts.pp | |
parent | 87162a8cc3e47996160f85e1807f75b9ad741bc8 (diff) | |
parent | c0f46562b70777b9a4a39429d94c49e869150c64 (diff) | |
download | puppet-dhcp-93895f1f039956ec9d02df511aaeaed885ae34bf.tar.gz puppet-dhcp-93895f1f039956ec9d02df511aaeaed885ae34bf.tar.bz2 |
Merge pull request #5 from raphink/dev/cleanup
Cleanup, refactor…
Diffstat (limited to 'manifests/hosts.pp')
-rw-r--r-- | manifests/hosts.pp | 65 |
1 files changed, 49 insertions, 16 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'], |