Skip to content

Instantly share code, notes, and snippets.

@norrs
Created October 28, 2012 18:06
Show Gist options
  • Save norrs/3969322 to your computer and use it in GitHub Desktop.
Save norrs/3969322 to your computer and use it in GitHub Desktop.
class dns::server($master_zones=undef,$slave_zones=undef, $options="default") {
package { "bind9":
ensure => "installed",
}
file { "/etc/bind/db.d":
ensure => directory,
owner => "bind",
group => "bind",
mode => "0755",
require => Package['bind9'],
}
file { "named.conf.options":
path => "/etc/bind/named.conf.options",
source => "puppet:///modules/dns/named.conf.options-$options",
require => Package['bind9'],
}
file { "named.conf.local":
path=> "/etc/bind/named.conf.local",
source => "puppet:///modules/dns/named.conf.local",
require => Package['bind9'],
}
file { "zone.masters":
path => "/etc/bind/zone.masters",
content=> template("dns/zone.masters.erb"),
require => Package['bind9'],
}
file { "zone.slaves":
path => "/etc/bind/zone.slaves",
content=> template("dns/zone.slaves.erb"),
require => Package['bind9'],
}
define zonefile() {
if $name!="" and $name!="," {
file { "tmp.db.$name":
path => "/tmp/$title",
owner => "bind",
group => "bind",
mode => "0644",
source => "puppet:///modules/dns/db.$title",
require => File["/etc/bind/db.d"],
}
exec { "zonecheck.helper.$name":
command => "cp /tmp/$name /tmp/helper.$name",
path => "/usr/bin:/usr/sbin:/bin",
refreshonly => true,
subscribe => File["tmp.db.$name"],
before => Exec["zonecheck.$name"],
}
exec { "zonecheck.$name":
command => "sh -c 'echo named-checkzone $name /tmp/$name Failed, check your zonefile && exit 1'",
path => "/usr/bin:/usr/sbin:/bin",
logoutput => true,
loglevel => err,
unless => "named-checkzone $name /tmp/$name",
}
#logoutput => on_failure,
exec { "mv-zone-$name":
command => "cp /tmp/helper.$name /etc/bind/db.d/$name",
path => "/usr/bin:/usr/sbin:/bin",
logoutput => true,
subscribe => File["tmp.db.$name"],
refreshonly => true,
require => Exec["zonecheck.helper.$name"],
onlyif => "named-checkzone $name /tmp/helper.$name",
notify => Exec["zone-reload-$name"],
}
exec { "zone-reload-$name":
command => "rndc reload $name",
path => "/usr/bin:/usr/sbin:/bin",
logoutput => true,
refreshonly => true,
require => Exec["mv-zone-$name"],
}
File["tmp.db.$name"] -> Exec["zonecheck.$name"] -> Exec["mv-zone-$name"] -> Exec["zone-reload-$name"]
# exec { "zone-reload-$name":
# command => "rndc reload $name",
# onlyif => [ "named-checkzone $name /tmp/$name",
# "cp /tmp/$name /etc/bind/db.d/$name",
# ],
# path => "/usr/bin:/usr/sbin:/bin",
# logoutput => false,
# require => File["tmp.db.$name"],
# }
}
}
$master_zone_keys = split(inline_template("<%= master_zones.keys.join(',') %>"), ",")
zonefile { $master_zone_keys: }
zonefile { $slave_zones: }
service { "bind9":
enable => true,
ensure => running,
hasstatus => true,
hasrestart => true,
require => [ Package['bind9'], File['named.conf.options'], File['named.conf.local'], File['zone.masters'],
File['zone.slaves'] ],
subscribe => File['named.conf.options'],
}
}
zone.masters.template thingie:
<% if @master_zones then %>
<% master_zones.each do |zone,allow_transfers| %>
zone "<%= zone %>" {
type master;
file "/etc/bind/db.d/<%= zone %>";
# <%= allow_transfers %>
<% if not allow_transfers.nil? and not allow_transfers.empty? then %>
allow-transfer {
<% allow_transfers.each do |ip| %>
<%= ip %>;
<% end %>
};
notify yes;
<% end %>
};
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment