-
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 (sed version) #45
Changes from 4 commits
47fc592
b2dcdb4
d3f8af7
1c4a7f0
c38b234
81fc115
e3817f1
f8b0b15
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
define dns::zone ( | ||
$soa = "${::fqdn}.", | ||
$soa_email = "root.${::fqdn}.", | ||
$serial = false, | ||
$zone_ttl = '604800', | ||
$zone_refresh = '604800', | ||
$zone_retry = '86400', | ||
|
@@ -16,44 +15,61 @@ | |
$ensure = present | ||
) { | ||
|
||
validate_array($allow_transfer) | ||
include dns::server::params | ||
|
||
$zone_serial = $serial ? { | ||
false => inline_template('<%= Time.now.to_i %>'), | ||
default => $serial | ||
} | ||
$cfg_dir = $dns::server::params::cfg_dir | ||
|
||
validate_array($allow_transfer) | ||
|
||
$zone = $reverse ? { | ||
true => "${name}.in-addr.arpa", | ||
default => $name | ||
} | ||
|
||
$zone_file = "/etc/bind/zones/db.${name}" | ||
$zone_file = "${cfg_dir}/zones/db.${name}" | ||
$zone_file_stage = "${zone_file}.stage" | ||
|
||
if $ensure == absent { | ||
file { $zone_file: | ||
ensure => absent, | ||
} | ||
} else { | ||
# Zone Database | ||
concat { $zone_file: | ||
|
||
# Create "fake" zone file without zone-serial | ||
concat { $zone_file_stage: | ||
owner => 'bind', | ||
group => 'bind', | ||
mode => '0644', | ||
require => [Class['concat::setup'], Class['dns::server']], | ||
notify => Class['dns::server::service'] | ||
notify => Exec["bump-${zone}-serial"] | ||
} | ||
concat::fragment{"db.${name}.soa": | ||
target => $zone_file, | ||
target => $zone_file_stage, | ||
order => 1, | ||
content => template("${module_name}/zone_file.erb") | ||
} | ||
|
||
# Generate real zone from stage file through replacement _SERIAL_ template | ||
# to current timestamp. A real zone file will be updated only at change of | ||
# the stage file, thanks to this serial is updated only in case of need. | ||
$zone_serial = inline_template('<%= Time.now.to_i %>') | ||
exec { "bump-${zone}-serial": | ||
command => "sed '8s/_SERIAL_/${zone_serial}/' ${zone_file_stage} > ${zone_file}", | ||
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 change only line num 8 (sed '8s/...'). It is safe, but demands care with a zone_file.erb template. 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. That seems ok to me. 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 checked code by lint and corrected all warnings except this line (correct version not committed now). Warning for this line:
There is a need to correct this warning? 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. Eh, its ok. |
||
path => ['/bin', '/sbin', '/usr/bin', '/usr/sbin'], | ||
refreshonly => true, | ||
provider => posix, | ||
user => 'bind', | ||
group => 'bind', | ||
require => Class['dns::server::install'], | ||
notify => Class['dns::server::service'], | ||
} | ||
} | ||
|
||
# Include Zone in named.conf.local | ||
concat::fragment{"named.conf.local.${name}.include": | ||
ensure => $ensure, | ||
target => '/etc/bind/named.conf.local', | ||
target => "${cfg_dir}/named.conf.local", | ||
order => 3, | ||
content => template("${module_name}/zone.erb") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
let(:title) { 'test.com' } | ||
|
||
context 'passing something other than an array' do | ||
let :facts do { :concat_basedir => '/dne', } end | ||
let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end | ||
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. include dns::server::params in zone.pp require fact osfamily 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. That is fine. |
||
let :params do { :allow_transfer => '127.0.0.1' } end | ||
|
||
it 'should fail input validation' do | ||
|
@@ -13,7 +13,7 @@ | |
end | ||
|
||
context 'passing an array to data' do | ||
let :facts do { :concat_basedir => '/dne', } end | ||
let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end | ||
let :params do | ||
{ :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ] } | ||
end | ||
|
@@ -36,6 +36,19 @@ | |
with_content(/2001:db8::\/32/) | ||
} | ||
|
||
it { | ||
should contain_concat('/etc/bind/zones/db.test.com.stage') | ||
} | ||
|
||
it { should contain_concat__fragment('db.test.com.soa'). | ||
with_content(/_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. There is a method to check only the 8th line for pattern? 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. Not that I know of, but I'm pretty happy with this part. If someone breaks the method of bumping serials, this test will complain. |
||
} | ||
|
||
it { | ||
should contain_exec('bump-test.com-serial'). | ||
with_refreshonly('true') | ||
} | ||
|
||
end | ||
|
||
end | ||
|
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.
I use external variable $dns::server::params::cfg_dir and without this include tests don't pass.
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.
Use
In your test block instead.