Install and manage a dhcp server with puppet.
Please read manifests/classes/dhcp.pp for more informations about usage.
--- /dev/null
+/*
+
+= 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"
+ }
+
+}
--- /dev/null
+/*
+
+= 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",
+ }
+ }
+}
--- /dev/null
+/*
+
+= 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",
+ }
+ }
+ }
+}
--- /dev/null
+/*
+
+= 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 }
+ }
+}
--- /dev/null
+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"),
+ }
+}
--- /dev/null
+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",
+ }
+
+}
--- /dev/null
+import "classes/*.pp"
+import "definitions/*.pp"
--- /dev/null
+# 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;
+
--- /dev/null
+host <%=name%> {
+ hardware ethernet <%=mac%>;
+<% if fixed_address -%>
+ fixed-address <%=fixed_address%>;
+<% else -%>
+ fixed-address <%=name%>;
+<% end -%>
+}
--- /dev/null
+# 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 %>
+}