-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update zone-serial only on changing zone-records #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
validate_array($allow_transfer) | ||
|
||
$cfg_dir = $dns::server::params::cfg_dir | ||
|
||
$zone_serial = $serial ? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can set serial of zone manually (compatibility issue), but serial number will be updated only if records changed. Probably we need to drop support of setting serial number by hand in future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, in this PR you can drop support for setting the serial by hand. It doesn't make sense to have that when under puppet control. |
||
false => inline_template('<%= Time.now.to_i %>'), | ||
default => $serial | ||
|
@@ -28,26 +30,49 @@ | |
default => $name | ||
} | ||
|
||
$zone_file = "/etc/bind/zones/db.${name}" | ||
$zone_dir = "${cfg_dir}/zones" | ||
$zone_file = "${zone_dir}/db.${name}" | ||
$zone_file_data = "${zone_file}.data" | ||
|
||
if $ensure == absent { | ||
file { $zone_file: | ||
ensure => absent, | ||
} | ||
} else { | ||
# Zone Database | ||
concat { $zone_file: | ||
owner => 'bind', | ||
group => 'bind', | ||
mode => '0644', | ||
require => [Class['concat::setup'], Class['dns::server']], | ||
notify => Class['dns::server::service'] | ||
} | ||
concat::fragment{"db.${name}.soa": | ||
target => $zone_file, | ||
order => 1, | ||
content => template("${module_name}/zone_file.erb") | ||
} | ||
# Splitting zone file on two parts: zone-soa (soa record) and zone-data (all other records). | ||
# This is to update zone_serial only by need (then zone-data updated). | ||
|
||
$soa_exec_cmdline = template("${module_name}/soa_exec_cmdline.erb") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this place i create command line for zone_soa.sh (it's necessary because we have unknown numbers of nameservers, i.e. different number of arguments for script). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about this. I kinda liked your previous approach better. This approach is pretty confusing:
This is pretty complicated. What if you took a different approach:
I think that is more straightforward, still converges, and has only 1 intermediate step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't know another way to generate cmdline with a different numbers of args.
What if you took a different approach:
Hmm... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The big difference is we are not generating a large command line. The only thing we would be executing would be sed. Se would have concat make zonefile.staging and sed would be creating zonefile. It is true that both methods achieve the same effect, I'm just suggesting the sed method is much easier to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main problem in exec with echo was output redirection ">" and pipes "|". Variant with sed has similar problem :( $nameservers_str = inline_template("<% @nameservers.each do |nameserver| -%> <%= nameserver %><% end -%>"),
exec { "soa-${zone}":
command => "$cfg_dir/puppet-scripts/zone_soa.sh $zone $soa $soa_email $zone_serial $zone_ttl $zone_refresh $zone_retry $zone_expire $zone_minimum $nameservers_str",
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need a special command based on a template with lots of arguments. We only care about the serial. Other parts can be handled in the ERB like normal. $zone_file = '/tmp/zone.staging'
$time = inline_template('<%= Time.now.to_i %>')
exec { "Bump serials on ${zone}":
command => "/bin/sed 's/SERIAL/${time}/' $zone_file > /tmp/zone",
provider => 'shell',
} |
||
|
||
exec { "soa-${zone}": | ||
command => "$soa_exec_cmdline", | ||
path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"], | ||
refreshonly => true, | ||
require => Class['dns::server::install'], | ||
notify => Class['dns::server::service'], | ||
} | ||
# Set correct rights on file generated by exec{soa-$zone:} | ||
file { $zone_file: | ||
ensure => file, | ||
owner => $dns::owner, | ||
group => $dns::group, | ||
mode => 0644, | ||
require => Exec["soa-${zone}"], | ||
} | ||
|
||
# Generate ${zone_name}.data file for static zones and request refresh exec on changes | ||
concat { $zone_file_data: | ||
owner => $dns::owner, | ||
group => $dns::group, | ||
mode => '644', | ||
require => Class['dns::server::install'], | ||
notify => Exec["soa-${zone}"], | ||
} | ||
concat::fragment{"db.${zone}.data-header": | ||
target => $zone_file_data, | ||
order => 1, | ||
content => template("${module_name}/zone_data_header.erb") | ||
} | ||
} | ||
|
||
# Include Zone in named.conf.local | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= @cfg_dir %>/puppet-scripts/zone_soa.sh <%= @zone %> <%= @soa %> <%= @soa_email %> <%= @zone_serial %> <%= @zone_ttl %> <%= @zone_refresh %> <%= @zone_retry %> <%= @zone_expire %> <%= @zone_minimum %><% @nameservers.each do |nameserver| -%> <%= nameserver %><% end -%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; ttl: <%= @zone_ttl %>, soa: <%= @soa %>, soa_email: <%= @soa_email %> | ||
; zone_refresh: <%= @zone_refresh %>, zone_retry: <%= @zone_retry %> | ||
; zone_expire: <%= @zone_expire %>, zone_minimum: <%= @zone_minimum %> | ||
; | ||
; nameservers: <% @nameservers.each do |nameserver| -%><%= nameserver %> <% end %> | ||
; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
# This is "template" for Puppet. It needs to make SOA header of DNS zone. | ||
# | ||
# Usage: | ||
# zone-soa.sh <zone_name> <soa> <soa_email> <zone_serial> <zone_ttl> <zone_refresh> <zone_retry> <zone_expire> <zone_minimum> <ns1> ... <nsN> | ||
|
||
ZONE_NAME=$1 | ||
SOA=$2 | ||
SOA_EMAIL=$3 | ||
ZONE_SERIAL=$4 | ||
ZONE_TTL=$5 | ||
ZONE_REFRESH=$6 | ||
ZONE_RETRY=$7 | ||
ZONE_EXPIRE=$8 | ||
ZONE_MINIMUM=$9 | ||
|
||
cat > "<%= @cfg_dir %>/zones/db.${ZONE_NAME}" <<EOF | ||
; | ||
; BIND data file for $ZONE_NAME zone. | ||
; File managed by puppet. | ||
; | ||
\$ORIGIN ${ZONE_NAME}. | ||
\$TTL $ZONE_TTL | ||
@ IN SOA ${SOA}. ${SOA_EMAIL}. ( | ||
$ZONE_SERIAL ; Serial | ||
$ZONE_REFRESH ; Refresh | ||
$ZONE_RETRY ; Retry | ||
$ZONE_EXPIRE ; Expire | ||
$ZONE_MINIMUM ) ; Negative Cache TTL | ||
; | ||
EOF | ||
|
||
shift 9 | ||
while [ "$#" -gt "0" ]; do | ||
NAMESERVER=$1 | ||
echo "@ IN NS $NAMESERVER." >> "<%= @cfg_dir %>/zones/db.${ZONE_NAME}" | ||
shift | ||
done | ||
|
||
cat >> "<%= @cfg_dir %>/zones/db.${ZONE_NAME}" <<EOF | ||
; | ||
\$INCLUDE /etc/bind/zones/db.${ZONE_NAME}.data | ||
EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to have all these requires. Puppet will auto-require a parent directory.