Created
February 20, 2013 11:40
-
-
Save norrs/4994946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment