Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Just an idea.

Zone template (zonefile):

$TTL 300S
@                       IN SOA  dnsserver (
                              0 ; SERIAL
                          28800 ; Refresh 8 hours
                           7200 ; Retry every 2 hours
                         604800 ; Expire after a week
                         3600 ) ; ttl of 1 hour

@                       IN NS   ns1
                        IN NS   ns2
                        IN NS   ns3
$INCLUDE <%= @includefile %>

Puppet module (you can wrap the following section into 'define'):

file {"/path/to/${zonefile}":
   ensure  => present,
   replace => false,
   content => template('zonefile.erb'),

file {"/path/to/${includefile}":
   ensure  => present,
   content => template('includefile.erb')
   notify  => Exec["serial increment: ${zonefile}"],

exec {"serial incrememnt: ${zonefile}":
   command     => "NEW_SERIAL=\"$( /bin/date +%s )\"; /bin/sed -i.bak \"s/[0-9]\+ ; SERIAL/$NEW_SERIAL ; SERIAL/g\" /path/to/${zonefile}",
   refreshonly => true,
   require     => File["/path/to/${zonefile}"],
  1. Deploy 'zonefile' if it doesn't exist, but do not overwrite if it already exists
  2. Deploy 'includefile' and notify Exec to change the serial number in 'zonefile'
  3. If 'zonefile' already exists and if notified, generate a new serial (e.g. unix time) and replace it in the 'zonefile'

The 'Exec' pretty much performs the following bash command:

NEW_SERIAL="$( date +%s )"
sed -i.bak "s/[0-9]\+ ; SERIAL/$NEW_SERIAL ; SERIAL/g" /path/to/zonefile

I am pretty sure you could do the same thing with Puppet parser code (Ruby), but this is just a simple idea how to do what you need.