]> gitweb.fluxo.info Git - puppet-dhcp.git/commitdiff
New module: dhcp
authorCédric Jeanneret <cedric.jeanneret@camptocamp.com>
Thu, 4 Nov 2010 13:02:31 +0000 (14:02 +0100)
committerCédric Jeanneret <cedric.jeanneret@camptocamp.com>
Thu, 4 Nov 2010 13:02:31 +0000 (14:02 +0100)
Install and manage a dhcp server with puppet.
Please read manifests/classes/dhcp.pp for more informations about usage.

files/empty/.place_holder [new file with mode: 0644]
manifests/classes/dhcp-base.pp [new file with mode: 0644]
manifests/classes/dhcp-debian.pp [new file with mode: 0644]
manifests/classes/dhcp-variables.pp [new file with mode: 0644]
manifests/classes/dhcp.pp [new file with mode: 0644]
manifests/definitions/dhcp-host.pp [new file with mode: 0644]
manifests/definitions/dhcp-subnet.pp [new file with mode: 0644]
manifests/init.pp [new file with mode: 0644]
templates/dhcpd.conf.squeeze.erb [new file with mode: 0644]
templates/host.conf.erb [new file with mode: 0644]
templates/subnet.conf.erb [new file with mode: 0644]

diff --git a/files/empty/.place_holder b/files/empty/.place_holder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/manifests/classes/dhcp-base.pp b/manifests/classes/dhcp-base.pp
new file mode 100644 (file)
index 0000000..4e1497e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+
+= Class dhcp::base
+Do NOT include this class - it won't work at all.
+Set variables for package name and so on.
+This class should be inherited in dhcp::$operatingsystem.
+
+*/
+class dhcp::base {
+  include dhcp::variables
+  package {"dhcp-server":
+    ensure => present,
+    name   => $dhcp::variables::srv_dhcpd,
+  }
+
+  service {"dhcpd":
+    name    => $dhcp::variables::srv_dhcpd,
+    ensure  => running,
+    enable  => true,
+    require => Package["dhcp-server"],
+  }
+
+  common::concatfilepart {"00-base":
+    file    => "${dhcp::variables::config_dir}/dhcpd.conf",
+    ensure  => present,
+    require => Package["dhcp-server"],
+    notify  => Service["dhcpd"],
+  }
+
+  file {"subnet-config-dir":
+    path   => "${dhcp::variables::config_dir}/subnets",
+    ensure => directory,
+    require => Package["dhcp-server"],
+    notify  => Service["dhcpd"],
+    recurse => true,
+    purge   => true,
+    force   => true,
+    source  => "puppet:///dhcp/empty"
+  }
+
+  file {"dhcp-config-dir":
+    path   => "${dhcp::variables::config_dir}/hosts.d",
+    ensure => directory,
+    require => Package["dhcp-server"],
+    recurse => true,
+    purge   => true,
+    force   => true,
+    source  => "puppet:///dhcp/empty"
+  }
+
+}
diff --git a/manifests/classes/dhcp-debian.pp b/manifests/classes/dhcp-debian.pp
new file mode 100644 (file)
index 0000000..1d35cbc
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+
+= Class: dhcp::debian
+Installs a dhcp server on debian system.
+
+This class should not be included as is, please include "dhcp" instead.
+
+*/
+class dhcp::debian inherits dhcp::base {
+
+  Common::Concatfilepart["00-base"] {
+    content => $lsbdistcodename ? {
+      squeeze => template('dhcp/dhcpd.conf.squeeze.erb'),
+      lenny   => template('dhcp/dhcpd.conf.lenny.erb'),
+    }
+  }
+
+  Service["dhcpd"] {
+    pattern => $lsbdistcodename ? {
+      squeeze => "/usr/sbin/dhcpd",
+      lenny   => "/usr/sbin/dhcpd3",
+    }
+  }
+}
diff --git a/manifests/classes/dhcp-variables.pp b/manifests/classes/dhcp-variables.pp
new file mode 100644 (file)
index 0000000..e189ae6
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+
+= Class: dhcp::variables
+Do NOT include this class - it won't do anything.
+Set variables for names and paths
+
+*/
+class dhcp::variables {
+  case $operatingsystem {
+    Debian: {
+      $config_dir = $lsbdistcodename? {
+        lenny   => "/etc/dhcp3",
+        squeeze => "/etc/dhcp",
+      }
+
+      $srv_dhcpd = $lsbdistcodename? {
+        lenny   => "dhcp3-server",
+        squeeze => "isc-dhcp-server",
+      }
+    }
+  }
+}
diff --git a/manifests/classes/dhcp.pp b/manifests/classes/dhcp.pp
new file mode 100644 (file)
index 0000000..9ae7b9f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+
+= Class: dhcp
+Simple OS wrapper. Include this to install a dhcp server on your host.
+
+Requires:
+  module "common": git://github.com/camptocamp/puppet-common.git
+
+Required arguments:
+  *$dhcpd_domain_name*: domain-name option
+  *$dhcpd_dns_servers*: domain-name-servers option
+
+facultative argument:
+  *$dhcpd_ddns_update*: ddns-update-style option
+  *$dhcpd_ddns_authoritative*: set it if you want that your DHCP server is authoritative
+
+Example:
+node "dhcp.toto.ltd" {
+  $dhcpd_domain_name = 'toto.ltd'
+  $dhcpd_dns_servers = '192.168.21.1'
+  include dhcp
+  
+  dhcp::subnet {"192.168.20.0":
+    ensure => present,
+    bcast => "192.168.20.255",
+    dns   => "192.168.21.1, 10.26.22.1",
+    other_opt => ['filename "pxelinux.0";', 'next-server 192.168.10.1;'],
+    inc   => true,
+  }
+
+  dhcp::host {"titi-eth0":
+    ensure => present,
+    mac    => "0e:18:fa:fe:d9:00",
+    subnet => "192.168.20.0",
+    fixed_address => "192.168.10.52",
+  }
+}
+*/
+class dhcp {
+  case $operatingsystem {
+    Debian: { include dhcp::debian }
+  }
+}
diff --git a/manifests/definitions/dhcp-host.pp b/manifests/definitions/dhcp-host.pp
new file mode 100644 (file)
index 0000000..747fa7c
--- /dev/null
@@ -0,0 +1,10 @@
+define dhcp::host($ensure=present,$mac,$subnet,$fixed_address=false) {
+  include dhcp::variables
+  common::concatfilepart {$name:
+    ensure => $ensure,
+    notify => Service["dhcpd"],
+    file   => "${dhcp::variables::config_dir}/hosts.d/${subnet}.conf",
+    require => Dhcp::Subnet[$subnet],
+    content => template("dhcp/host.conf.erb"),
+  }
+}
diff --git a/manifests/definitions/dhcp-subnet.pp b/manifests/definitions/dhcp-subnet.pp
new file mode 100644 (file)
index 0000000..46c55ae
--- /dev/null
@@ -0,0 +1,33 @@
+define dhcp::subnet(
+  $ensure=present,
+  $bcast,
+  $dns,
+  $netmask=false,
+  $domain_name=false,
+  $inc=false,
+  $routeurs=false,
+  $netbios_dns=false,
+  $subnet_mask=false,
+  $other_opt=false,
+  $deny=false) {
+  include dhcp::variables
+
+  if $inc {
+    $to_inc = "${dhcp::variables::config_dir}/hosts.d/${name}.conf"
+  }
+
+  file {"${dhcp::variables::config_dir}/subnets/${name}.conf":
+    ensure => $ensure,
+    owner  => root,
+    group  => root,
+    content => template("dhcp/subnet.conf.erb"),
+    notify  => Service["dhcpd"],
+  }
+  
+  common::concatfilepart {"${name}":
+    file => "${dhcp::variables::config_dir}/dhcpd.conf",
+    ensure => $ensure,
+    content => "include \"${dhcp::variables::config_dir}/subnets/${name}.conf\";\n",
+  }
+
+}
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644 (file)
index 0000000..6cc1969
--- /dev/null
@@ -0,0 +1,2 @@
+import "classes/*.pp"
+import "definitions/*.pp"
diff --git a/templates/dhcpd.conf.squeeze.erb b/templates/dhcpd.conf.squeeze.erb
new file mode 100644 (file)
index 0000000..865c04c
--- /dev/null
@@ -0,0 +1,31 @@
+# File managed by puppet
+
+# The ddns-updates-style parameter controls whether or not the server will
+# attempt to do a DNS update when a lease is confirmed. We default to the
+# behavior of the version 2 packages ('none', since DHCP v2 didn't
+# have support for DDNS.)
+<% if has_variable?('dhcpd_ddns_update') -%>
+ddns-update-style <%=dhcpd_ddns_update%>;
+<% else -%>
+ddns-update-style none;
+<% end -%>
+
+# option definitions common to all supported networks...
+option domain-name "<%=dhcpd_domain_name%>";
+option domain-name-servers <%=dhcpd_dns_servers%>;
+
+default-lease-time 600;
+max-lease-time 7200;
+
+# If this DHCP server is the official DHCP server for the local
+# network, the authoritative directive should be uncommented.
+<% if has_variable?('dhcpd_ddns_authoritative') -%>
+authoritative;
+<% else -%>
+#authoritative;
+<% end -%>
+
+# Use this to send dhcp log messages to a different log file (you also
+# have to hack syslog.conf to complete the redirection).
+log-facility local7;
+
diff --git a/templates/host.conf.erb b/templates/host.conf.erb
new file mode 100644 (file)
index 0000000..2cdb4af
--- /dev/null
@@ -0,0 +1,8 @@
+host <%=name%> {
+  hardware ethernet <%=mac%>;
+<% if fixed_address -%>
+  fixed-address <%=fixed_address%>;
+<% else -%>
+  fixed-address <%=name%>;
+<% end -%>
+}
diff --git a/templates/subnet.conf.erb b/templates/subnet.conf.erb
new file mode 100644 (file)
index 0000000..a0a9d29
--- /dev/null
@@ -0,0 +1,39 @@
+# File managed by puppet
+
+<% if netmask -%>
+subnet <%=name%> netmask <%=netmask%> {
+<% else -%>
+subnet <%=name%> netmask <%=netmask_eth0%> {
+<% end -%>
+<% if routeurs -%>
+  option routers <%=routeurs%>;
+<% else -%>
+  option routers <%=network_eth0%>;
+<% end -%>
+<% if subnet_mask -%>
+  option subnet-mask <%=subnet_mask%>;
+<% else -%>
+  option subnet-mask <%=netmask%>;
+<% end -%>
+  option broadcast-address <%=bcast%>;
+  option domain-name-servers <%=dns%>;
+<% if domain_name -%>
+  option domain-name "<%=domain_name%>";
+<% else -%>
+  option domain-name "<%=domain%>";
+<% end -%>
+<% if netbios_dns -%>
+  option netbios-name-servers <%=netbios_dns%>;
+<% else -%>
+  option netbios-name-servers <%=network_eth0%>;
+<% end -%>
+<% if deny -%>
+  deny <%=deny%>;
+<% end -%>
+<% if inc -%>
+  include "<%=to_inc%>";
+<% end -%>
+<% if other_opt and not other_opt.empty? -%>
+<%= other_opt.collect! {|i| "  #{i}" }.join("\n") -%>
+<% end %>
+}