forked from ajjahn/puppet-dns
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ajjahn#138 from jearls/add-all-option-to-ptr-param…
…eter Add `all` and `first` values to `ptr` parameter of `dns::record::a`
- Loading branch information
Showing
3 changed files
with
300 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# == Definition: dns::record::ptr::by_ip | ||
# | ||
# This type is defined to allow the dns::record::a resource type to | ||
# use pre-4.x 'iteration' to create reverse ptr records for hosts with | ||
# multiple ip addresses. | ||
# | ||
# === Parameters | ||
# | ||
# * `$ip` | ||
# The ip address for the ptr record. Defaults to the resource title. | ||
# | ||
# * `$host` | ||
# The (unqualified) host pointed to by this ptr record. | ||
# | ||
# * `$ttl` | ||
# The TTL of the records to be created. Defaults to undefined. | ||
# | ||
# * `$zone` | ||
# The domain of the host pointed to by this ptr record. | ||
# | ||
# === Actions | ||
# | ||
# Reformats the $ip, $host, $zone parameters to create a `dns::record::ptr` | ||
# resource | ||
# | ||
# === Examples | ||
# | ||
# @example | ||
# dns::record::ptr::by_ip { '192.168.128.42': | ||
# host => 'server' , | ||
# zone => 'example.com' , | ||
# } | ||
# | ||
# turns into: | ||
# | ||
# @example | ||
# dns::record::ptr { '42.128.168.192.IN-ADDR.ARPA': | ||
# host => '42' , | ||
# zone => '128.168.192.IN-ADDR.ARPA' , | ||
# data => 'server.example.com' , | ||
# } | ||
# | ||
# --- | ||
# @example | ||
# dns::record::ptr::by_ip { [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ]: | ||
# host => 'multihomed-server' , | ||
# zone => 'example.com' , | ||
# } | ||
# | ||
# turns into: | ||
# | ||
# @example | ||
# dns::record::ptr { '68.128.168.192.IN-ADDR.ARPA': | ||
# host => '68' , | ||
# zone => '128.168.192.IN-ADDR.ARPA' , | ||
# data => 'multihomed-server.example.com' , | ||
# | ||
# @example | ||
# dns::record::ptr { '69.128.168.192.IN-ADDR.ARPA': | ||
# host => '69' , | ||
# zone => '128.168.192.IN-ADDR.ARPA' , | ||
# data => 'multihomed-server.example.com' , | ||
# | ||
# @example | ||
# dns::record::ptr { '70.128.168.192.IN-ADDR.ARPA': | ||
# host => '70' , | ||
# zone => '128.168.192.IN-ADDR.ARPA' , | ||
# data => 'multihomed-server.example.com' , | ||
# } | ||
|
||
define dns::record::ptr::by_ip ( | ||
$host, | ||
$zone, | ||
$ttl = undef , | ||
$ip = $name ) { | ||
|
||
# split the IP address up into three host/zone pairs based on class A, B, or C splits: | ||
# For IP address A.B.C.D, | ||
# class C => host D / zone C.B.A.IN-ADDR.ARPA | ||
# class B => host D.C / zone B.A.IN-ADDR.ARPA | ||
# class A => host D.C.B / zone A.IN-ADDR.ARPA | ||
$class_C_zone = inline_template('<%= @ip.split(".").reverse()[1..3].join(".") %>.IN-ADDR.ARPA') | ||
$class_C_host = inline_template('<%= @ip.split(".").reverse()[0..0].join(".") %>') | ||
$class_B_zone = inline_template('<%= @ip.split(".").reverse()[2..3].join(".") %>.IN-ADDR.ARPA') | ||
$class_B_host = inline_template('<%= @ip.split(".").reverse()[0..1].join(".") %>') | ||
$class_A_zone = inline_template('<%= @ip.split(".").reverse()[3..3].join(".") %>.IN-ADDR.ARPA') | ||
$class_A_host = inline_template('<%= @ip.split(".").reverse()[0..2].join(".") %>') | ||
|
||
# choose the most specific defined reverse zone file (class C, then B, then A). | ||
# Default to class C if none are defined. | ||
if defined(Dns::Zone[$class_C_zone]) { | ||
$reverse_zone = $class_C_zone | ||
$octet = $class_C_host | ||
} elsif defined(Dns::Zone[$class_B_zone]) { | ||
$reverse_zone = $class_B_zone | ||
$octet = $class_B_host | ||
} elsif defined(Dns::Zone[$class_A_zone]) { | ||
$reverse_zone = $class_A_zone | ||
$octet = $class_A_host | ||
} else { | ||
$reverse_zone = $class_C_zone | ||
$octet = $class_C_host | ||
} | ||
|
||
dns::record::ptr { "${octet}.${reverse_zone}": | ||
host => $octet, | ||
zone => $reverse_zone, | ||
ttl => $ttl , | ||
data => "${host}.${zone}" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
require 'spec_helper' | ||
|
||
describe 'dns::record::a', :type => :define do | ||
let(:title) { 'atest' } | ||
let(:facts) { { :concat_basedir => '/tmp' } } | ||
|
||
context 'passing a single ip address with ptr=>false' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => '192.168.128.42', | ||
:ptr => false, | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.42$/) } | ||
it { should_not contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.42.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record') } | ||
end | ||
|
||
context 'passing a single ip address with ptr=>true' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => '192.168.128.42', | ||
:ptr => true, | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.42$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.42.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^42\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing a single ip address with ptr=>all' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => '192.168.128.42', | ||
:ptr => 'all', | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.42$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.42.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^42\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing multiple ip addresses with ptr=>false' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => false, | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.68\natest\s+IN\s+A\s+192\.168\.128\.69\natest\s+IN\s+A\s+192\.168\.128\.70$/) } | ||
it { should_not contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record') } | ||
end | ||
|
||
context 'passing multiple ip addresses with ptr=>true' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => true, | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.68\natest\s+IN\s+A\s+192\.168\.128\.69\natest\s+IN\s+A\s+192\.168\.128\.70$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing multiple ip addresses with ptr=>all' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.example.com.atest,A,example.com.record').with_content(/^atest\s+IN\s+A\s+192\.168\.128\.68\natest\s+IN\s+A\s+192\.168\.128\.69\natest\s+IN\s+A\s+192\.168\.128\.70$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.69.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^69\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.70.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^70\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class A network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,192.IN-ADDR.ARPA.record').with_content(/^68\.128\.168\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class B network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,168.192.IN-ADDR.ARPA.record').with_content(/^68\.128\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class C network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "128.168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class A and class B network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "192.IN-ADDR.ARPA": }', | ||
'dns::zone { "168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,168.192.IN-ADDR.ARPA.record').with_content(/^68\.128\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class A and class C network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "192.IN-ADDR.ARPA": }', | ||
'dns::zone { "128.168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class B and class C network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "168.192.IN-ADDR.ARPA": }', | ||
'dns::zone { "128.168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
context 'passing ptr=>true with class A, class B and class C network defined' do | ||
let :params do { | ||
:host => 'atest', | ||
:zone => 'example.com', | ||
:data => [ '192.168.128.68', '192.168.128.69', '192.168.128.70' ], | ||
:ptr => 'all', | ||
} end | ||
let :pre_condition do [ | ||
'dns::zone { "192.IN-ADDR.ARPA": }', | ||
'dns::zone { "168.192.IN-ADDR.ARPA": }', | ||
'dns::zone { "128.168.192.IN-ADDR.ARPA": }', | ||
] end | ||
it { should_not raise_error } | ||
it { should contain_concat__fragment('db.128.168.192.IN-ADDR.ARPA.68.128.168.192.IN-ADDR.ARPA,PTR,128.168.192.IN-ADDR.ARPA.record').with_content(/^68\s+IN\s+PTR\s+atest\.example\.com\.$/) } | ||
end | ||
|
||
end | ||
|