aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifests/host.pp28
-rw-r--r--manifests/hosts.pp52
-rw-r--r--templates/host.conf.erb20
3 files changed, 65 insertions, 35 deletions
diff --git a/manifests/host.pp b/manifests/host.pp
deleted file mode 100644
index 969ecc4..0000000
--- a/manifests/host.pp
+++ /dev/null
@@ -1,28 +0,0 @@
-# = Definition: dhcp::host
-#
-# Create dhcp configuration for a host
-#
-# Arguments:
-# *$mac*: host MAC address (mandatory)
-# *$subnet*: subnet in which we want to add this host
-# *$fixed_address*: host fixed address (if not set, takes $name)
-#
-#
-define dhcp::host (
- $mac,
- $subnet,
- $ensure = present,
- $fixed_address = false,
- $options = false
-) {
-
- include dhcp::params
-
- concat::fragment {"dhcp.host.${name}":
- ensure => $ensure,
- target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf",
- content => template('dhcp/host.conf.erb'),
- notify => Service['dhcpd'],
- }
-
-}
diff --git a/manifests/hosts.pp b/manifests/hosts.pp
new file mode 100644
index 0000000..b159449
--- /dev/null
+++ b/manifests/hosts.pp
@@ -0,0 +1,52 @@
+# = Definition: dhcp::hosts
+#
+# Creates a dhcp configuration for 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:
+# {
+# <host1> => {
+# options => false,
+# fixed_address => false,
+# interfaces => {
+# eth0 => 'mac-address',
+# eth1 => 'mac-address',
+# wlan0 => 'mac-address',
+# wlan1 => 'mac-address',
+# …,
+# }
+# },
+# <host2> => {
+# options => false,
+# fixed_address => false,
+# interfaces => {
+# eth0 => 'mac-address',
+# eth1 => 'mac-address',
+# wlan0 => 'mac-address',
+# wlan1 => 'mac-address',
+# …,
+# }
+# },
+# …,
+# }
+#
+define dhcp::hosts (
+ $hash_data,
+ $subnet,
+ $global_options = false,
+ $template = 'dhcp/host.conf.erb',
+) {
+
+ include dhcp::params
+
+ concat::fragment {"dhcp.host.${name}":
+ target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf",
+ content => template($template),
+ notify => Service['dhcpd'],
+ }
+}
diff --git a/templates/host.conf.erb b/templates/host.conf.erb
index 20ba6e6..e6a7073 100644
--- a/templates/host.conf.erb
+++ b/templates/host.conf.erb
@@ -1,11 +1,17 @@
-host <%=name%> {
- hardware ethernet <%=mac%>;
-<% if fixed_address -%>
- fixed-address <%=fixed_address%>;
+<%- @hash_data.sort.each do |host, datas| -%>
+<%- datas.fetch('interfaces').sort.each do |if_name, if_mac| -%>
+host <%= host %>-<%= if_name %> {
+ hardware ethernet <%= if_mac %>;
+<% if datas.fetch('fixed_address', false) -%>
+ fixed-address <%= datas.fetch('fixed_address') %>;
<% else -%>
- fixed-address <%=name%>;
+ fixed-address <%= host %>;
<% end -%>
-<% if options -%>
- <%=options%>
+<% if datas.fetch('option', false) -%>
+ <%= datas.fetch('option') %>
+<% elsif @global_options -%>
+ <%= @global_options %>
<% end -%>
}
+<% end -%>
+<% end -%>