# Install DNS server. # class dns::server { if $operatingsystem != "OpenBSD" { package { "bind": name => $operatingsystem ? { "ubuntu" => "bind9", default => "bind-chroot", } } } case $operatingsystem { "centos","fedora": { $confdir = "/var/named/chroot/etc" } "ubuntu": { $confdir = "/etc/bind" } default: { $confdir = "/var/named/etc" } } file { "${confdir}/rndc.key": ensure => present, mode => 0640, owner => "root", group => $operatingsystem ? { "ubuntu" => "bind", default => "named", }, require => $operatingsystem ? { "openbsd" => undef, default => Package["bind"], }, } exec { "rndc-confgen": command => "rndc-confgen -a -t ${confdir}", path => "/bin:/usr/bin:/sbin:/usr/sbin", unless => "test -s ${confdir}/rndc.key", require => File["${confdir}/rndc.key"], } case $operatingsystem { "centos","fedora": { file { "/etc/rndc.key": ensure => "${confdir}/rndc.key", owner => "root", group => "root", require => Exec["rndc-confgen"], } } } service { "named": name => $operatingsystem ? { "ubuntu" => "bind9", default => "named", }, ensure => running, enable => true, status => "/usr/sbin/rndc status", stop => $operatingsystem ? { "openbsd" => "pkill -u named", default => undef, }, start => $operatingsystem ? { "openbsd" => "/usr/sbin/named", default => undef, }, require => Exec["rndc-confgen"], } define populate_zones() { $zone = $name file { "${confdir}/db.${zone}": ensure => present, content => template("dns/db.erb"), mode => 0640, owner => "root", group => "bind", require => Package["bind"], notify => Service["named"], } file { "${confdir}/db.${zone}-dynamic": ensure => present, source => [ "puppet:///files/dns/db.${zone}-dynamic.${homename}", "puppet:///files/dns/empty", ], mode => 0640, owner => "root", group => "bind", require => Package["bind"], notify => Service["named"], } file { "${confdir}/db.${zone}-static": ensure => present, source => [ "puppet:///files/dns/db.${zone}-static.${homename}", "puppet:///files/dns/empty", ], mode => 0640, owner => "root", group => "bind", require => Package["bind"], notify => Service["named"], } } case $operatingsystem { "ubuntu": { $ipaddr = $dns_listener_ipaddr file { "${confdir}/named.conf.local": ensure => present, content => template("dns/named.conf.local.erb"), mode => 0640, owner => "root", group => "bind", require => Package["bind"], notify => Service["named"], } file { "${confdir}/named.conf.options": ensure => present, content => template("dns/named.conf.options.erb"), mode => 0640, owner => "root", group => "bind", require => Package["bind"], notify => Service["named"], } populate_zones { $dns_zones: } } default: { file { "${confdir}/named.conf": ensure => present, source => [ "puppet:///files/dns/named.conf.${fqdn}", "puppet:///files/dns/named.conf", ], mode => 0640, owner => "root", group => "named", require => $operatingsystem ? { openbsd => undef, default => Package["bind"], }, notify => Service["named"], } } } } # Install dynamic DNS update script # # === Global variables # # $dns_nsupdate_name: # FQDN to update into DNS. # # $dns_nsupdate_key: # DNS key to use when updating entry. Usually in format: # # for example: # gw1.example.com. sZ6GgTZLBX83LXCoo # # $dns_nsupdate_server: # DNS server address where to update entry. # # $dns_nsupdate_zone: # Zone name to update. Defaults to domain part of # $dns_nsupdate_name variable. # class dns::nsupdate { file { "/usr/local/sbin/nsupdate.sh": ensure => present, content => template("dns/nsupdate.sh.erb"), mode => 0700, owner => root, group => $operatingsystem ? { openbsd => wheel, default => root, }, } cron { "nsupdate": ensure => present, command => "/usr/local/sbin/nsupdate.sh", minute => "*/5", require => File["/usr/local/sbin/nsupdate.sh"], } }