From 1b013e0d4b79e4bdfa3dd713e52e90fa0b7a6670 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 08:59:35 -0400 Subject: [PATCH 01/78] shuffle update_policy conditionals to prevent duplicate directives --- templates/zone.conf.epp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/zone.conf.epp b/templates/zone.conf.epp index b825786..3b22256 100644 --- a/templates/zone.conf.epp +++ b/templates/zone.conf.epp @@ -86,16 +86,16 @@ zone "<%= $zone_name %>" { serial-update-method <%= $serial_update_method %>; <%- } -%> <%- if $update_policy { - if 'local' in $update_policy { -%> - update-policy local; - <%- } - $update_policy_rules = $update_policy - 'local' - unless $update_policy_rules.empty { -%> update-policy { + <%- if 'local' in $update_policy { -%> + local; + <%- $update_policy_rules = $update_policy - 'local' -%> + <%- } -%> + unless $update_policy_rules.empty { -%> <%- $update_policy_rules.each |$rule| { -%> <%= $rule['permission'] %> <%= $rule['identity'] %> <%= $rule['ruletype'] %> <%= $rule['name'] %> <%= $rule['types'] %>; <%- } -%> - }; <%- } -%> + }; <%- } -%> }; From 24cccfae3a0f139d5c97721137b87240ddc82998 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 09:29:38 -0400 Subject: [PATCH 02/78] Revert "shuffle update_policy conditionals to prevent duplicate directives" This reverts commit 1b013e0d4b79e4bdfa3dd713e52e90fa0b7a6670. --- templates/zone.conf.epp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/zone.conf.epp b/templates/zone.conf.epp index 3b22256..b825786 100644 --- a/templates/zone.conf.epp +++ b/templates/zone.conf.epp @@ -86,16 +86,16 @@ zone "<%= $zone_name %>" { serial-update-method <%= $serial_update_method %>; <%- } -%> <%- if $update_policy { + if 'local' in $update_policy { -%> + update-policy local; + <%- } + $update_policy_rules = $update_policy - 'local' + unless $update_policy_rules.empty { -%> update-policy { - <%- if 'local' in $update_policy { -%> - local; - <%- $update_policy_rules = $update_policy - 'local' -%> - <%- } -%> - unless $update_policy_rules.empty { -%> <%- $update_policy_rules.each |$rule| { -%> <%= $rule['permission'] %> <%= $rule['identity'] %> <%= $rule['ruletype'] %> <%= $rule['name'] %> <%= $rule['types'] %>; <%- } -%> - <%- } -%> }; + <%- } -%> <%- } -%> }; From ee0d710707cbb9c0dfc728e48f6f7abb50424432 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 14:32:41 -0400 Subject: [PATCH 03/78] RR creation via local nsupdate --- lib/puppet/provider/resource_record/resource_record.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 6dc4788..d1d7531 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -20,6 +20,12 @@ def get(context) def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") + cmd = "echo 'zone #{@resource[:zone]} + update delete #{@resource[:record]} #{@resource[:type]} + update add #{@resource[:record]} #{@resource[:ttl]} #{@resource[:type]} #{@resource[:data]} + send + ' | nsupdate -l" + system(cmd) end def update(context, name, should) From b5cdadbdd617eeaff99497b042d1a54e1f9a962e Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 14:39:11 -0400 Subject: [PATCH 04/78] RR creation via local nsupdate --- lib/puppet/provider/resource_record/resource_record.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index d1d7531..974219a 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -20,9 +20,9 @@ def get(context) def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") - cmd = "echo 'zone #{@resource[:zone]} - update delete #{@resource[:record]} #{@resource[:type]} - update add #{@resource[:record]} #{@resource[:ttl]} #{@resource[:type]} #{@resource[:data]} + cmd = "echo 'zone #{should[:zone]} + update delete #{should[:record]} #{should[:type]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send ' | nsupdate -l" system(cmd) From 50ef2642daf246ca67a83ba4b2cbb78413baf515 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 15:34:27 -0400 Subject: [PATCH 05/78] RR deletion via local nsupdate, some ramblings on create --- .../provider/resource_record/resource_record.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 974219a..53e6942 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -6,6 +6,10 @@ class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def get(context) context.debug('Returning pre-canned example data') + + #Trigger a dumpdb on agent run and destroy on completion. + # + [ { name: 'foo', @@ -20,6 +24,13 @@ def get(context) def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") + + #Temporary measure to make these "just work". This will regenerate every single manually defined + #record on each agent run, which is...okay? At a certain point scale makes that less than ideal. + #I also dislike having to send an individual nsupdate for each record. With the current structure, + #it'd be preferable to create a /tmp/ file for each managed zone on run, append all records we + #need to act on, then do an nsupdate for each zone file and subsequently destroy them. + cmd = "echo 'zone #{should[:zone]} update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} @@ -34,6 +45,11 @@ def update(context, name, should) def delete(context, name) context.notice("Deleting '#{name}'") + cmd = "echo 'zone #{should[:zone]} + update delete #{should[:record]} #{should[:type]} + send + ' | nsupdate -l" + system(cmd) end def canonicalize(_context, resources) From d1d5ae8cd0edcfaf3e6dc08e7ea4f4f48e5ddcd9 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 10:52:31 -0400 Subject: [PATCH 06/78] add resource record management to provider --- .../resource_record/resource_record.rb | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 53e6942..4bb1349 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -4,22 +4,40 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider + def initialize + system('rndc', 'dumpdb', '-zones') + end def get(context) context.debug('Returning pre-canned example data') - #Trigger a dumpdb on agent run and destroy on completion. - # - - [ - { - name: 'foo', - ensure: 'present', - }, - { - name: 'bar', - ensure: 'present', - }, - ] + #FIXME: Trigger a dumpdb on agent run and destroy on completion instead of every RR operation + #system('rndc', 'dumpdb', '-zones') + records = [] + #FIXME: location varies based on config/OS + File.readlines('/var/cache/bind/named_dump.db').each do |line| + if line[0] == ';' && line.length > 17 + currentzone = line[/(?:.*?')(.*?)\//,1] + else + line = line.split(' ', 5) + rr = {} + rr[:label] = line[0] + rr[:ttl] = line[1] + rr[:scope] = line[2] + rr[:type] = line[3] + rr[:data] = line[4] + rr[:zone] = currentzone + records << { + title: "#{rr[:name]} #{rr[:type]} #{rr[:data]}", + ensure: 'present', + record: "#{rr[:label]}", + zone: "#{rr[:zone]}", + type: "#{rr[:type]}", + data: "#{rr[:data]}", + ttl: "#{rr[:ttl]}", + } + end + end + records end def create(context, name, should) @@ -32,7 +50,6 @@ def create(context, name, should) #need to act on, then do an nsupdate for each zone file and subsequently destroy them. cmd = "echo 'zone #{should[:zone]} - update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send ' | nsupdate -l" @@ -41,12 +58,18 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name}' with #{should.inspect}") - end + cmd = "echo 'zone #{should[:zone]} + update delete #{should[:record]} #{should[:type]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + ' | nsupdate -l" + system(cmd) + end def delete(context, name) context.notice("Deleting '#{name}'") cmd = "echo 'zone #{should[:zone]} - update delete #{should[:record]} #{should[:type]} + update delete #{should[:record]} #{should[:type]} #{should[:data]} send ' | nsupdate -l" system(cmd) From 0d24911c5677cd3c398f365895d7282963cc339c Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 10:59:10 -0400 Subject: [PATCH 07/78] add resource record management to provider --- lib/puppet/provider/resource_record/resource_record.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 4bb1349..44e6527 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,10 +5,11 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize + context.notice("Generating fresh zone dump...") system('rndc', 'dumpdb', '-zones') end def get(context) - context.debug('Returning pre-canned example data') + context.notice("Getting existing resource records...") #FIXME: Trigger a dumpdb on agent run and destroy on completion instead of every RR operation #system('rndc', 'dumpdb', '-zones') @@ -17,8 +18,10 @@ def get(context) File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 17 currentzone = line[/(?:.*?')(.*?)\//,1] + context.debug("current zone: #{currentzone}") else line = line.split(' ', 5) + context.debug("get line for parsing: #{line.to_s}") rr = {} rr[:label] = line[0] rr[:ttl] = line[1] From 58c840b971bc8dbb549a06b4fe730ff3f26e9421 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 11:01:33 -0400 Subject: [PATCH 08/78] add resource record management to provider --- lib/puppet/provider/resource_record/resource_record.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 44e6527..256684e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,7 +5,6 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize - context.notice("Generating fresh zone dump...") system('rndc', 'dumpdb', '-zones') end def get(context) From 6c8d17df03e52f9fb13dda5705d78678a6e59ef1 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 11:05:32 -0400 Subject: [PATCH 09/78] resource record parsing: trim newline --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 256684e..3f91e80 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -18,8 +18,8 @@ def get(context) if line[0] == ';' && line.length > 17 currentzone = line[/(?:.*?')(.*?)\//,1] context.debug("current zone: #{currentzone}") - else - line = line.split(' ', 5) + elsif line[0] != ';' + line = line.strip.split(' ', 5) context.debug("get line for parsing: #{line.to_s}") rr = {} rr[:label] = line[0] From 0cd794f32f8642adc66c5e7390a4f2fe692f38fb Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 11:09:25 -0400 Subject: [PATCH 10/78] resource record parsing: debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 3f91e80..2fde525 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -16,6 +16,7 @@ def get(context) #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 17 + context.debug("line for zone name: #{line}") currentzone = line[/(?:.*?')(.*?)\//,1] context.debug("current zone: #{currentzone}") elsif line[0] != ';' From d0f57b49e5de4fbfe18d71f87641e09b39050c34 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 11:11:56 -0400 Subject: [PATCH 11/78] resource record parsing: debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 2fde525..05dad18 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -15,7 +15,7 @@ def get(context) records = [] #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| - if line[0] == ';' && line.length > 17 + if line[0] == ';' && line.length > 18 context.debug("line for zone name: #{line}") currentzone = line[/(?:.*?')(.*?)\//,1] context.debug("current zone: #{currentzone}") From 2ee2a44d8ed7e49fb112f3a7c5df77aa2870a422 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 16:20:49 -0400 Subject: [PATCH 12/78] resource record parsing: incorrect attribute name --- .../provider/resource_record/resource_record.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 05dad18..779d084 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -10,8 +10,6 @@ def initialize def get(context) context.notice("Getting existing resource records...") - #FIXME: Trigger a dumpdb on agent run and destroy on completion instead of every RR operation - #system('rndc', 'dumpdb', '-zones') records = [] #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| @@ -21,7 +19,6 @@ def get(context) context.debug("current zone: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) - context.debug("get line for parsing: #{line.to_s}") rr = {} rr[:label] = line[0] rr[:ttl] = line[1] @@ -30,7 +27,6 @@ def get(context) rr[:data] = line[4] rr[:zone] = currentzone records << { - title: "#{rr[:name]} #{rr[:type]} #{rr[:data]}", ensure: 'present', record: "#{rr[:label]}", zone: "#{rr[:zone]}", @@ -46,11 +42,9 @@ def get(context) def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") - #Temporary measure to make these "just work". This will regenerate every single manually defined - #record on each agent run, which is...okay? At a certain point scale makes that less than ideal. - #I also dislike having to send an individual nsupdate for each record. With the current structure, - #it'd be preferable to create a /tmp/ file for each managed zone on run, append all records we - #need to act on, then do an nsupdate for each zone file and subsequently destroy them. + #I dislike having to send an individual nsupdate for each record, it'd be preferable to + #build a request for each managed zone on run, append all records we + #need to act on, then send a bulk nsupdate for each zone cmd = "echo 'zone #{should[:zone]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} From 71b2fce62684caee33cdddfedc3b6b880288d50d Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 25 Oct 2021 16:24:27 -0400 Subject: [PATCH 13/78] readd preemptive deletion to nsupdate in RR provider create method --- lib/puppet/provider/resource_record/resource_record.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 779d084..f579064 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -46,7 +46,9 @@ def create(context, name, should) #build a request for each managed zone on run, append all records we #need to act on, then send a bulk nsupdate for each zone + #the delete line is temporary to prevent duplicate creations while this is in progress cmd = "echo 'zone #{should[:zone]} + update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send ' | nsupdate -l" From 16a5ee95c1e699e42d1ca0d4a329f6617f83ad35 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 08:24:10 -0400 Subject: [PATCH 14/78] RR canonicalize debug --- lib/puppet/provider/resource_record/resource_record.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index f579064..509f76c 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -76,9 +76,12 @@ def delete(context, name) def canonicalize(_context, resources) resources.each do |r| - r[:record] = r[:record].downcase - r[:zone] = r[:zone].downcase - r[:type] = r[:type].upcase + _context.notice("Record: #{r[:record]}") + #r[:record] = r[:record].downcase + _context.notice("Zone: #{r[:zone]}") + #r[:zone] = r[:zone].downcase + _context.notice("Type: #{r[:type]}") + #r[:type] = r[:type].upcase end end end From 3a6eff0865a193e062c563890dd4dfee7ff78d42 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 08:43:26 -0400 Subject: [PATCH 15/78] RR additional debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 509f76c..5aefc20 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -21,11 +21,17 @@ def get(context) line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] + context.debug("New RR\nRR label: #{rr[:label]}") rr[:ttl] = line[1] + context.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] + context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] + context.debug("RR type: #{rr[:type]}") rr[:data] = line[4] + context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + context.debug("RR zone: #{rr[:zone]}") records << { ensure: 'present', record: "#{rr[:label]}", @@ -36,6 +42,7 @@ def get(context) } end end + context.debug("#{records.inspect}") records end From 05ef4bab720e34eef66c90e616f159f6e58f98ea Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 08:45:20 -0400 Subject: [PATCH 16/78] zone scope mishap --- lib/puppet/provider/resource_record/resource_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 5aefc20..a2dc585 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -11,6 +11,7 @@ def get(context) context.notice("Getting existing resource records...") records = [] + currentzone = "" #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 From 9cbc1ef577346032e280564a218ec86ce15e5306 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 08:54:01 -0400 Subject: [PATCH 17/78] trailing dot for zone getter as given by manifest --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index a2dc585..b8341f5 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -31,7 +31,7 @@ def get(context) context.debug("RR type: #{rr[:type]}") rr[:data] = line[4] context.debug("RR data: #{rr[:data]}") - rr[:zone] = currentzone + rr[:zone] = currentzone << . context.debug("RR zone: #{rr[:zone]}") records << { ensure: 'present', From 5b1c2129de1c78375e221fd0dee3e8b8d8d3e83b Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 08:55:04 -0400 Subject: [PATCH 18/78] trailing dot for zone getter as given by manifest --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index b8341f5..5a6325e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -31,7 +31,7 @@ def get(context) context.debug("RR type: #{rr[:type]}") rr[:data] = line[4] context.debug("RR data: #{rr[:data]}") - rr[:zone] = currentzone << . + rr[:zone] = currentzone << '.' context.debug("RR zone: #{rr[:zone]}") records << { ensure: 'present', From 199d3e4948aeaea8b73d1e31bd7f34c19b0ea83a Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 09:02:42 -0400 Subject: [PATCH 19/78] trailing dot for zone getter as given by manifest --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 5a6325e..94b94fc 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -31,7 +31,7 @@ def get(context) context.debug("RR type: #{rr[:type]}") rr[:data] = line[4] context.debug("RR data: #{rr[:data]}") - rr[:zone] = currentzone << '.' + rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") records << { ensure: 'present', From 69f725a703fbedd11264259b14df68edeb6ffe24 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 09:24:02 -0400 Subject: [PATCH 20/78] local nsupdate explicit IPv4 to avoid requiring additional config --- lib/puppet/provider/resource_record/resource_record.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 94b94fc..44f5b27 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -59,7 +59,7 @@ def create(context, name, should) update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send - ' | nsupdate -l" + ' | nsupdate -4 -l" system(cmd) end @@ -69,7 +69,7 @@ def update(context, name, should) update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send - ' | nsupdate -l" + ' | nsupdate -4 -l" system(cmd) end @@ -78,7 +78,7 @@ def delete(context, name) cmd = "echo 'zone #{should[:zone]} update delete #{should[:record]} #{should[:type]} #{should[:data]} send - ' | nsupdate -l" + ' | nsupdate -4 -l" system(cmd) end From c4acb59e010e715f38a477400dcc8a814db06684 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 10:29:36 -0400 Subject: [PATCH 21/78] add explicit title in provider getter --- lib/puppet/provider/resource_record/resource_record.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 44f5b27..4787b1f 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -34,6 +34,7 @@ def get(context) rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") records << { + title: "#{rr[:label]}", ensure: 'present', record: "#{rr[:label]}", zone: "#{rr[:zone]}", @@ -84,11 +85,11 @@ def delete(context, name) def canonicalize(_context, resources) resources.each do |r| - _context.notice("Record: #{r[:record]}") + _context.debug("Record: #{r[:record]}") #r[:record] = r[:record].downcase - _context.notice("Zone: #{r[:zone]}") + _context.debug("Zone: #{r[:zone]}") #r[:zone] = r[:zone].downcase - _context.notice("Type: #{r[:type]}") + _context.debug("Type: #{r[:type]}") #r[:type] = r[:type].upcase end end From 695672b65694c2210eb0b275739a047d9b53f155 Mon Sep 17 00:00:00 2001 From: griggi Date: Tue, 26 Oct 2021 10:37:31 -0400 Subject: [PATCH 22/78] more explicit composite namevars --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- lib/puppet/type/resource_record.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 4787b1f..b8ced4e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -34,7 +34,7 @@ def get(context) rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") records << { - title: "#{rr[:label]}", + title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]}", ensure: 'present', record: "#{rr[:label]}", zone: "#{rr[:zone]}", diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 2f7b764..270ca0d 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -21,8 +21,8 @@ features: ['canonicalize'], title_patterns: [ { - desc: 'name, zone (everything after the first dot), space, type', - pattern: %r{^(?.*?[^.])\.(?.*[^ ]\.) +(?.*)$}, + desc: 'full name, space, zone (explicitly defined), space, type', + pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?.*)$}, }, { desc: 'name and zone (everything after the first dot)', From d51176f265150f59f3942b62be48814383e6c3de Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:06:27 -0400 Subject: [PATCH 23/78] update canonicalize for parsed TXT records and trailing newlines from hiera --- .../provider/resource_record/resource_record.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index b8ced4e..0b0c185 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,24 +5,24 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize + context.debug("Generating zone dump...") system('rndc', 'dumpdb', '-zones') end def get(context) - context.notice("Getting existing resource records...") + context.debug("Parsing dump for existing resource records...") records = [] currentzone = "" #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - context.debug("line for zone name: #{line}") currentzone = line[/(?:.*?')(.*?)\//,1] - context.debug("current zone: #{currentzone}") + context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] - context.debug("New RR\nRR label: #{rr[:label]}") + context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] context.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] @@ -86,11 +86,12 @@ def delete(context, name) def canonicalize(_context, resources) resources.each do |r| _context.debug("Record: #{r[:record]}") - #r[:record] = r[:record].downcase + r[:record] = r[:record].downcase.strip _context.debug("Zone: #{r[:zone]}") - #r[:zone] = r[:zone].downcase + r[:zone] = r[:zone].downcase _context.debug("Type: #{r[:type]}") - #r[:type] = r[:type].upcase + r[:type] = r[:type].upcase + r[:data] = r[:data].tr('"', '') end end end From a4ba0e01e75fa9bb92e0b0c553e484cc59202e03 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:09:22 -0400 Subject: [PATCH 24/78] update canonicalize for parsed TXT records and trailing newlines from hiera --- lib/puppet/provider/resource_record/resource_record.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 0b0c185..d0bf27e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,7 +5,6 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize - context.debug("Generating zone dump...") system('rndc', 'dumpdb', '-zones') end def get(context) From 4482d63cacb899a2a30f575b2f0178d365d1550e Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:10:45 -0400 Subject: [PATCH 25/78] RR canonicalize debug print --- lib/puppet/provider/resource_record/resource_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index d0bf27e..aefde46 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -91,6 +91,7 @@ def canonicalize(_context, resources) _context.debug("Type: #{r[:type]}") r[:type] = r[:type].upcase r[:data] = r[:data].tr('"', '') + _context.debug("Data: #{r[:zone]}") end end end From 8c0f35b05aaa99540177aadc43e910c72e998e43 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:12:17 -0400 Subject: [PATCH 26/78] update canonicalize for parsed TXT records and trailing newlines from hiera --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index aefde46..6579132 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -90,7 +90,7 @@ def canonicalize(_context, resources) r[:zone] = r[:zone].downcase _context.debug("Type: #{r[:type]}") r[:type] = r[:type].upcase - r[:data] = r[:data].tr('"', '') + r[:data] = r[:data].tr('\"', '') _context.debug("Data: #{r[:zone]}") end end From bf555fe86e19f986b565d2c23c969bd2017ceef1 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:28:37 -0400 Subject: [PATCH 27/78] update canonicalize for parsed TXT records and trailing newlines from hiera --- .../resource_record/resource_record.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 6579132..503f051 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -84,13 +84,24 @@ def delete(context, name) def canonicalize(_context, resources) resources.each do |r| + _context.debug("Record: #{r[:record]}") - r[:record] = r[:record].downcase.strip + if r[:record].respond_to?(:to_str) + r[:record] = r[:record].downcase.strip + else + _context.debug("Record is not a string") + end _context.debug("Zone: #{r[:zone]}") - r[:zone] = r[:zone].downcase + if r[:zone].respond_to?(:to_str) + r[:zone] = r[:zone].downcase + end _context.debug("Type: #{r[:type]}") - r[:type] = r[:type].upcase - r[:data] = r[:data].tr('\"', '') + if r[:type].respond_to?(:to_str) + r[:type] = r[:type].upcase + end + if r[:type].respond_to?(:to_str) + r[:data] = r[:data].tr('\"', '') + end _context.debug("Data: #{r[:zone]}") end end From 2d7dd5bb4a835c344ee5e823724f3cdceeeeb06f Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 15:32:11 -0400 Subject: [PATCH 28/78] update canonicalize for parsed TXT records and trailing newlines from hiera --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 503f051..a8da5be 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -28,7 +28,7 @@ def get(context) context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] context.debug("RR type: #{rr[:type]}") - rr[:data] = line[4] + rr[:data] = line[4].tr('\"', '') context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") From 7d0359fe90799d6192e6a44aa1d0112b0a234ab8 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 16:28:17 -0400 Subject: [PATCH 29/78] delete method tweaks --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index a8da5be..d15a957 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -75,8 +75,8 @@ def update(context, name, should) def delete(context, name) context.notice("Deleting '#{name}'") - cmd = "echo 'zone #{should[:zone]} - update delete #{should[:record]} #{should[:type]} #{should[:data]} + cmd = "echo 'zone #{name[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} send ' | nsupdate -4 -l" system(cmd) From efff8d9bea2e3fe2912253e20bb6befbfa74492a Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 27 Oct 2021 16:29:48 -0400 Subject: [PATCH 30/78] delete method tweaks --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index d15a957..55f6269 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -66,7 +66,7 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name}' with #{should.inspect}") cmd = "echo 'zone #{should[:zone]} - update delete #{should[:record]} #{should[:type]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send ' | nsupdate -4 -l" From 3c9b7ec6257eeb65d199b809456d34978e1f2509 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 08:16:45 -0400 Subject: [PATCH 31/78] per-zone RR purging --- manifests/zone.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/zone.pp b/manifests/zone.pp index 7b36d50..f01686e 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -208,6 +208,7 @@ $resource_records.each |$rrname, $attribs| { resource_record { $rrname: zone => $zone_name, + purge => $purge, * => $attribs, } } From ba4042c14f850955293a4849e272a29d49738a3d Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 08:23:27 -0400 Subject: [PATCH 32/78] Revert "per-zone RR purging" This reverts commit 3c9b7ec6257eeb65d199b809456d34978e1f2509. --- manifests/zone.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index f01686e..7b36d50 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -208,7 +208,6 @@ $resource_records.each |$rrname, $attribs| { resource_record { $rrname: zone => $zone_name, - purge => $purge, * => $attribs, } } From a7ec58c5b488ab82e7e79a21ce8ba3ba8c02ba26 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 10:23:52 -0400 Subject: [PATCH 33/78] some conditionals to prevent avoidable errors --- lib/puppet/provider/resource_record/resource_record.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 55f6269..b419f52 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -28,7 +28,11 @@ def get(context) context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] context.debug("RR type: #{rr[:type]}") - rr[:data] = line[4].tr('\"', '') + if line[4].respond_to?(:to_str) + rr[:data] = line[4].tr('\"', '') + else + rr[:data] = line[4] + end context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") From 2e99d00da5f55a2da760180fc21936386d338cb7 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 10:42:17 -0400 Subject: [PATCH 34/78] canonicalize debug print --- lib/puppet/provider/resource_record/resource_record.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index b419f52..2a82473 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -89,24 +89,25 @@ def delete(context, name) def canonicalize(_context, resources) resources.each do |r| - _context.debug("Record: #{r[:record]}") + _context.debug("#{r.inspect}") + #_context.debug("Record: #{r[:record]}") if r[:record].respond_to?(:to_str) r[:record] = r[:record].downcase.strip else _context.debug("Record is not a string") end - _context.debug("Zone: #{r[:zone]}") + #_context.debug("Zone: #{r[:zone]}") if r[:zone].respond_to?(:to_str) r[:zone] = r[:zone].downcase end - _context.debug("Type: #{r[:type]}") + #_context.debug("Type: #{r[:type]}") if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end if r[:type].respond_to?(:to_str) r[:data] = r[:data].tr('\"', '') end - _context.debug("Data: #{r[:zone]}") + #_context.debug("Data: #{r[:data]}") end end end From b99d1b81e2f702086344ea56d08fb35dee6257e9 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 10:51:10 -0400 Subject: [PATCH 35/78] canonicalize debug print --- lib/puppet/provider/resource_record/resource_record.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 2a82473..54c205f 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -90,24 +90,18 @@ def canonicalize(_context, resources) resources.each do |r| _context.debug("#{r.inspect}") - #_context.debug("Record: #{r[:record]}") if r[:record].respond_to?(:to_str) r[:record] = r[:record].downcase.strip - else - _context.debug("Record is not a string") end - #_context.debug("Zone: #{r[:zone]}") if r[:zone].respond_to?(:to_str) r[:zone] = r[:zone].downcase end - #_context.debug("Type: #{r[:type]}") if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end - if r[:type].respond_to?(:to_str) + if r[:data].respond_to?(:to_str) r[:data] = r[:data].tr('\"', '') end - #_context.debug("Data: #{r[:data]}") end end end From 41af07aaa7fc00e7c31d97816ad2db11319c805b Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:19:54 -0400 Subject: [PATCH 36/78] PTR generation --- .../resource_record/resource_record.rb | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 54c205f..1d98c4e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'puppet/resource_api/simple_provider' - +require 'ipaddr' # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize @@ -53,7 +53,7 @@ def get(context) def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") - + #I dislike having to send an individual nsupdate for each record, it'd be preferable to #build a request for each managed zone on run, append all records we #need to act on, then send a bulk nsupdate for each zone @@ -63,8 +63,24 @@ def create(context, name, should) update delete #{should[:record]} #{should[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send + quit ' | nsupdate -4 -l" system(cmd) + + #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. + if should[:type] == "A" + fqdn = "#{record}" + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] + end + reverse = IPAddr.new("#{should[:data]}").reverse + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) + end end def update(context, name, should) @@ -73,8 +89,23 @@ def update(context, name, should) update delete #{name[:record]} #{name[:type]} #{name[:data]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send + quit ' | nsupdate -4 -l" system(cmd) + if should[:type] == "A" + fqdn = "#{record}" + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] + end + reverse_name = IPAddr.new("#{name[:data]}").reverse + reverse_should = IPAddr.new("#{should[:data]}").reverse + cmd = "echo 'update delete #{reverse_name} PTR + update add #{reverse_should} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) + end end def delete(context, name) @@ -82,8 +113,16 @@ def delete(context, name) cmd = "echo 'zone #{name[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} send + quit ' | nsupdate -4 -l" system(cmd) + if name[:type] == "A" + reverse = IPAddr.new("#{name[:data]}").reverse + cmd = "echo 'update delete #{reverse} PTR + send + quit + ' | nsupdate -4 -l" + end end def canonicalize(_context, resources) From 3c958b150d2c6e07c6d1b49638e34dcc05a87a29 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:24:05 -0400 Subject: [PATCH 37/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 1d98c4e..7d35954 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -85,6 +85,8 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name}' with #{should.inspect}") + context.debug("old: #{name.inspect}") + context.debug("new: #{should.inspect}") cmd = "echo 'zone #{should[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} From 7bb8d60b506ea295c845aa15ea97ce36d4cfbefe Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:28:12 -0400 Subject: [PATCH 38/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 7d35954..9646059 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -85,8 +85,8 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name}' with #{should.inspect}") - context.debug("old: #{name.inspect}") - context.debug("new: #{should.inspect}") + context.debug("old: #{name[:record]}") + context.debug("new: #{should[:record]}") cmd = "echo 'zone #{should[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} From 6e7a1d24fa39c7cea4f2c45b38fcf3a6e60970be Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:40:04 -0400 Subject: [PATCH 39/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 9646059..116af59 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -95,7 +95,7 @@ def update(context, name, should) ' | nsupdate -4 -l" system(cmd) if should[:type] == "A" - fqdn = "#{record}" + fqdn = "#{should[:record]}" if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end From 4b2c0831266c1f0400b567876342bc3d81487c7d Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:48:49 -0400 Subject: [PATCH 40/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 116af59..446cc47 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -101,6 +101,9 @@ def update(context, name, should) end reverse_name = IPAddr.new("#{name[:data]}").reverse reverse_should = IPAddr.new("#{should[:data]}").reverse + context.debug("fqdn: #{fqdn}") + context.debug("reverse_name: #{reverse_name}") + context.debug("reverse_should: #{reverse_should}") cmd = "echo 'update delete #{reverse_name} PTR update add #{reverse_should} PTR #{fqdn} send From ed0d71c8cc7b770ef073418c66fbe35d92d00e6f Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:55:10 -0400 Subject: [PATCH 41/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 446cc47..ddc7a15 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -69,11 +69,11 @@ def create(context, name, should) #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. if should[:type] == "A" - fqdn = "#{record}" + fqdn = should[:record] if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end - reverse = IPAddr.new("#{should[:data]}").reverse + reverse = IPAddr.new(should[:data]).reverse cmd = "echo 'update delete #{reverse} PTR update add #{reverse} PTR #{fqdn} send @@ -95,12 +95,12 @@ def update(context, name, should) ' | nsupdate -4 -l" system(cmd) if should[:type] == "A" - fqdn = "#{should[:record]}" + fqdn = should[:record] if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end - reverse_name = IPAddr.new("#{name[:data]}").reverse - reverse_should = IPAddr.new("#{should[:data]}").reverse + reverse_name = IPAddr.new(name[:data]).reverse + reverse_should = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") context.debug("reverse_name: #{reverse_name}") context.debug("reverse_should: #{reverse_should}") From 15ecc5469b5525b9ec197d351cab32d1f5a5fd3d Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 14:59:29 -0400 Subject: [PATCH 42/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index ddc7a15..9fed5af 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -99,6 +99,7 @@ def update(context, name, should) if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end + context.debug("IPs: #{name[:data] should[:data]}") reverse_name = IPAddr.new(name[:data]).reverse reverse_should = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") From c05c27a7439b51167f8a3693d229ab886d58d1c2 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 15:00:15 -0400 Subject: [PATCH 43/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 9fed5af..63bc41e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -99,7 +99,7 @@ def update(context, name, should) if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end - context.debug("IPs: #{name[:data] should[:data]}") + context.debug("IPs: #{name[:data]} #{should[:data]}") reverse_name = IPAddr.new(name[:data]).reverse reverse_should = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") From 0e79356ba1b47bec5845307b3f41784cfdb15a13 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 15:04:36 -0400 Subject: [PATCH 44/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 63bc41e..398087c 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -99,7 +99,7 @@ def update(context, name, should) if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end - context.debug("IPs: #{name[:data]} #{should[:data]}") + context.debug("IPs: old - #{name[:data]}| new - #{should[:data]}") reverse_name = IPAddr.new(name[:data]).reverse reverse_should = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") From 43118ea3b46746b371c1037429ae8753dd4feadc Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 15:08:08 -0400 Subject: [PATCH 45/78] PTR generation debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 398087c..5ab575b 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -84,7 +84,7 @@ def create(context, name, should) end def update(context, name, should) - context.notice("Updating '#{name}' with #{should.inspect}") + context.notice("Updating '#{name.inspect}' with #{should.inspect}") context.debug("old: #{name[:record]}") context.debug("new: #{should[:record]}") cmd = "echo 'zone #{should[:zone]} From fff8bb4e336c30933f545bbac5ecbb2a22331ea4 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 15:15:38 -0400 Subject: [PATCH 46/78] stop trying to access data we don't have --- .../resource_record/resource_record.rb | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 5ab575b..86c2369 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -85,10 +85,8 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name.inspect}' with #{should.inspect}") - context.debug("old: #{name[:record]}") - context.debug("new: #{should[:record]}") cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} + update delete #{name[:record]} #{name[:type]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send quit @@ -99,14 +97,11 @@ def update(context, name, should) if fqdn[fqdn.length-1] != "." fqdn = fqdn + should[:zone] end - context.debug("IPs: old - #{name[:data]}| new - #{should[:data]}") - reverse_name = IPAddr.new(name[:data]).reverse - reverse_should = IPAddr.new(should[:data]).reverse + reverse = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") - context.debug("reverse_name: #{reverse_name}") - context.debug("reverse_should: #{reverse_should}") - cmd = "echo 'update delete #{reverse_name} PTR - update add #{reverse_should} PTR #{fqdn} + context.debug("reverse: #{reverse}") + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} PTR #{fqdn} send quit ' | nsupdate -4 -l" @@ -117,18 +112,11 @@ def update(context, name, should) def delete(context, name) context.notice("Deleting '#{name}'") cmd = "echo 'zone #{name[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} + update delete #{name[:record]} #{name[:type]} send quit ' | nsupdate -4 -l" system(cmd) - if name[:type] == "A" - reverse = IPAddr.new("#{name[:data]}").reverse - cmd = "echo 'update delete #{reverse} PTR - send - quit - ' | nsupdate -4 -l" - end end def canonicalize(_context, resources) From 760bd086fc4617bb94f66fbad74f9ce70e7c347c Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 28 Oct 2021 15:18:48 -0400 Subject: [PATCH 47/78] Fix missing TTL on PTR nsupdate --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 86c2369..10c453f 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -75,7 +75,7 @@ def create(context, name, should) end reverse = IPAddr.new(should[:data]).reverse cmd = "echo 'update delete #{reverse} PTR - update add #{reverse} PTR #{fqdn} + update add #{reverse} #{should[:ttl]} PTR #{fqdn} send quit ' | nsupdate -4 -l" @@ -101,7 +101,7 @@ def update(context, name, should) context.debug("fqdn: #{fqdn}") context.debug("reverse: #{reverse}") cmd = "echo 'update delete #{reverse} PTR - update add #{reverse} PTR #{fqdn} + update add #{reverse} #{should[:ttl]} PTR #{fqdn} send quit ' | nsupdate -4 -l" From 4550e1322bc63942b608f37e1a4694dd3e3971e4 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 18 Oct 2021 08:59:35 -0400 Subject: [PATCH 48/78] implement resource record management --- .../resource_record/resource_record.rb | 134 +++++++++++++++--- lib/puppet/type/resource_record.rb | 4 +- 2 files changed, 119 insertions(+), 19 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 6dc4788..b497bae 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -1,40 +1,140 @@ # frozen_string_literal: true require 'puppet/resource_api/simple_provider' - +require 'ipaddr' # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider + def initialize + system('rndc', 'dumpdb', '-zones') + end def get(context) - context.debug('Returning pre-canned example data') - [ - { - name: 'foo', - ensure: 'present', - }, - { - name: 'bar', - ensure: 'present', - }, - ] + context.debug("Parsing dump for existing resource records...") + + records = [] + currentzone = "" + #FIXME: location varies based on config/OS + File.readlines('/var/cache/bind/named_dump.db').each do |line| + if line[0] == ';' && line.length > 18 + currentzone = line[/(?:.*?')(.*?)\//,1] + context.debug("current zone updated: #{currentzone}") + elsif line[0] != ';' + line = line.strip.split(' ', 5) + rr = {} + rr[:label] = line[0] + context.debug("----New RR---- label: #{rr[:label]}") + rr[:ttl] = line[1] + context.debug("RR TTL: #{rr[:ttl]}") + rr[:scope] = line[2] + context.debug("RR scope: #{rr[:scope]}") + rr[:type] = line[3] + context.debug("RR type: #{rr[:type]}") + if line[4].respond_to?(:to_str) + rr[:data] = line[4].tr('\"', '') + else + rr[:data] = line[4] + end + context.debug("RR data: #{rr[:data]}") + rr[:zone] = currentzone + '.' + context.debug("RR zone: #{rr[:zone]}") + records << { + title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]}", + ensure: 'present', + record: "#{rr[:label]}", + zone: "#{rr[:zone]}", + type: "#{rr[:type]}", + data: "#{rr[:data]}", + ttl: "#{rr[:ttl]}", + } + end + end + context.debug("#{records.inspect}") + records end def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") + + #I dislike having to send an individual nsupdate for each record, it'd be preferable to + #build a request for each managed zone on run, append all records we + #need to act on, then send a bulk nsupdate for each zone + + #the delete line is temporary to prevent duplicate creations while this is in progress + cmd = "echo 'zone #{should[:zone]} + update delete #{should[:record]} #{should[:type]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + system(cmd) + + #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. + if should[:type] == "A" + fqdn = should[:record] + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] + end + reverse = IPAddr.new(should[:data]).reverse + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} #{should[:ttl]} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) + end end def update(context, name, should) - context.notice("Updating '#{name}' with #{should.inspect}") - end + context.notice("Updating '#{name.inspect}' with #{should.inspect}") + cmd = "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + system(cmd) + if should[:type] == "A" + fqdn = should[:record] + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] + end + reverse = IPAddr.new(should[:data]).reverse + context.debug("fqdn: #{fqdn}") + context.debug("reverse: #{reverse}") + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} #{should[:ttl]} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) + end + end def delete(context, name) context.notice("Deleting '#{name}'") + cmd = "echo 'zone #{name[:zone]} + update delete #{name[:record]} #{name[:type]} + send + quit + ' | nsupdate -4 -l" + system(cmd) end def canonicalize(_context, resources) resources.each do |r| - r[:record] = r[:record].downcase - r[:zone] = r[:zone].downcase - r[:type] = r[:type].upcase + + _context.debug("#{r.inspect}") + if r[:record].respond_to?(:to_str) + r[:record] = r[:record].downcase.strip + end + if r[:zone].respond_to?(:to_str) + r[:zone] = r[:zone].downcase + end + if r[:type].respond_to?(:to_str) + r[:type] = r[:type].upcase + end + if r[:data].respond_to?(:to_str) + r[:data] = r[:data].tr('\"', '') + end end end end diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 2f7b764..270ca0d 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -21,8 +21,8 @@ features: ['canonicalize'], title_patterns: [ { - desc: 'name, zone (everything after the first dot), space, type', - pattern: %r{^(?.*?[^.])\.(?.*[^ ]\.) +(?.*)$}, + desc: 'full name, space, zone (explicitly defined), space, type', + pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?.*)$}, }, { desc: 'name and zone (everything after the first dot)', From 5540d9b0de8a18a70bd72b1d828f17de59e25816 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 10 Nov 2021 15:43:14 -0500 Subject: [PATCH 49/78] Include data in namevar for safe deletion of differing records with same origin --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- lib/puppet/type/resource_record.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 10c453f..f6734c6 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -86,7 +86,7 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name.inspect}' with #{should.inspect}") cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} send quit @@ -112,7 +112,7 @@ def update(context, name, should) def delete(context, name) context.notice("Deleting '#{name}'") cmd = "echo 'zone #{name[:zone]} - update delete #{name[:record]} #{name[:type]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} send quit ' | nsupdate -4 -l" diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 270ca0d..23a9e5b 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -20,9 +20,13 @@ EOS features: ['canonicalize'], title_patterns: [ + { + desc: 'full name, space, zone (explicitly defined), space, type, space, data', + pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?\w+) (?.*)$}, + }, { desc: 'full name, space, zone (explicitly defined), space, type', - pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?.*)$}, + pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?\w+)$}, }, { desc: 'name and zone (everything after the first dot)', @@ -61,6 +65,7 @@ data: { type: 'String', desc: 'The data for the resource record.', + behavior: :namevar, }, ttl: { type: 'Optional[String]', From 05d79014c7afa9ba04d7240cd182df57079c8700 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 10 Nov 2021 15:47:17 -0500 Subject: [PATCH 50/78] Include data in namevar for safe deletion of differing records with same origin --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 7fdba7d..3e04684 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -36,7 +36,7 @@ def get(context) rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") records << { - title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]}", + title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', record: "#{rr[:label]}", zone: "#{rr[:zone]}", From 1777e55a3e7023fb64ecebf1edf100c26084b5a0 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 13:36:35 -0500 Subject: [PATCH 51/78] Add allow-query to zone definitions --- manifests/zone.pp | 4 ++++ templates/zone.conf.epp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/manifests/zone.pp b/manifests/zone.pp index 7b36d50..8f46dc9 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -10,6 +10,8 @@ # # @param allow_update Which hosts are allowed to submit Dynamic DNS updates to the zone. # +# @param allow_query Hosts allowed to query the zone +# # @param also_notify list of IP addresses of name servers that are also sent NOTIFY messages # whenever a fresh copy of the zone is loaded, in addition to the servers listed in the zone’s NS # records. @@ -64,6 +66,7 @@ Pattern[/\.$/] $zone_name = $title, Optional[Array[Variant[Stdlib::Host, Stdlib::IP::Address]]] $allow_transfer = undef, Optional[Array[Variant[Stdlib::Host, Stdlib::IP::Address]]] $allow_update = undef, + Optional[Array[Variant[Stdlib::Host, Stdlib::IP::Address]]] $allow_query = undef, Optional[Array[Variant[Stdlib::Host, Stdlib::IP::Address]]] $also_notify = undef, Optional[Enum['allow', 'maintain', 'off']] $auto_dnssec = undef, Optional[Enum['IN', 'HS', 'hesiod', 'CHAOS']] $class = undef, @@ -107,6 +110,7 @@ 'zone_name' => $zone_name, 'allow_transfer' => $allow_transfer, 'allow_update' => $allow_update, + 'allow_query' => $allow_query, 'also_notify' => $also_notify, 'auto_dnssec' => $auto_dnssec, 'class' => $class, diff --git a/templates/zone.conf.epp b/templates/zone.conf.epp index b825786..ce2ac65 100644 --- a/templates/zone.conf.epp +++ b/templates/zone.conf.epp @@ -42,6 +42,13 @@ zone "<%= $zone_name %>" { <%- } -%> }; <%- } -%> + <%- if $allow_query { -%> + allow-query { + <%- $allow_query.each |$address_match_list_element| { -%> + <%= $address_match_list_element -%>; + <%- } -%> + }; + <%- } -%> <%- if $also_notify { -%> also-notify { <%- $also_notify.each |$address_match_list_element| { -%> From c25987207d3ee4d05b0a8d8e2cccb17192e9fb0b Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 14:10:51 -0500 Subject: [PATCH 52/78] primaries -> masters zone conf --- templates/zone.conf.epp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/zone.conf.epp b/templates/zone.conf.epp index ce2ac65..54fb7e7 100644 --- a/templates/zone.conf.epp +++ b/templates/zone.conf.epp @@ -76,7 +76,7 @@ zone "<%= $zone_name %>" { }; <%- } -%> <%- if $primaries { -%> - primaries { + masters { <%- $primaries.each |$primary| { -%> <%= $primary %>; <%- } -%> From 53ef175526659a7af4ed9e9df0a151decd1d8698 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 14:23:30 -0500 Subject: [PATCH 53/78] fix some canonicalization consistency --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 3e04684..98c1a4d 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -14,12 +14,12 @@ def get(context) #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - currentzone = line[/(?:.*?')(.*?)\//,1] + currentzone = line[/(?:.*?')(.*?)\//,1].downcase context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} - rr[:label] = line[0] + rr[:label] = line[0].downcase context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] context.debug("RR TTL: #{rr[:ttl]}") From 11088da62e0e3be7386c9ef23bedea38136ab6d2 Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 14:25:27 -0500 Subject: [PATCH 54/78] Revert "fix some canonicalization consistency" This reverts commit 53ef175526659a7af4ed9e9df0a151decd1d8698. --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 98c1a4d..3e04684 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -14,12 +14,12 @@ def get(context) #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - currentzone = line[/(?:.*?')(.*?)\//,1].downcase + currentzone = line[/(?:.*?')(.*?)\//,1] context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} - rr[:label] = line[0].downcase + rr[:label] = line[0] context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] context.debug("RR TTL: #{rr[:ttl]}") From 8dd6a220c57b8c0d62d714d635a64d13143e6c7e Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 14:27:29 -0500 Subject: [PATCH 55/78] fix some canonicalization consistency --- lib/puppet/provider/resource_record/resource_record.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 3e04684..9b28ddf 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -15,11 +15,13 @@ def get(context) File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 currentzone = line[/(?:.*?')(.*?)\//,1] + if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] + if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] context.debug("RR TTL: #{rr[:ttl]}") From df43d50432aeecbaa47707b01c916fb719a9654d Mon Sep 17 00:00:00 2001 From: griggi Date: Thu, 11 Nov 2021 14:28:22 -0500 Subject: [PATCH 56/78] fix some canonicalization consistency --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 9b28ddf..692105d 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -15,13 +15,13 @@ def get(context) File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 currentzone = line[/(?:.*?')(.*?)\//,1] - if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase + if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase end context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] - if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase + if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase end context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] context.debug("RR TTL: #{rr[:ttl]}") From dfd05e80a7e3f25dd5edcb6d00ed122482a3eb24 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 15 Nov 2021 09:26:26 -0500 Subject: [PATCH 57/78] Define resource record title to always match that generated by provider get --- manifests/zone.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index 8f46dc9..bce2f33 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -210,7 +210,7 @@ } $resource_records.each |$rrname, $attribs| { - resource_record { $rrname: + resource_record { "${attribs[record]} ${zone_name} ${attribs[type]} ${attribs[data]}": zone => $zone_name, * => $attribs, } From 5a418fe20061292b032f8c404b21f5888980b3d6 Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 15 Nov 2021 09:28:15 -0500 Subject: [PATCH 58/78] Define resource record title to always match that generated by provider get --- manifests/zone.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index bce2f33..e37ce92 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -210,7 +210,7 @@ } $resource_records.each |$rrname, $attribs| { - resource_record { "${attribs[record]} ${zone_name} ${attribs[type]} ${attribs[data]}": + resource_record { "${attribs['record']} ${zone_name} ${attribs['type']} ${attribs['data']}": zone => $zone_name, * => $attribs, } From 18aca36d6b1db38f7e18fdb0fc951fa12c000f1a Mon Sep 17 00:00:00 2001 From: griggi Date: Mon, 15 Nov 2021 10:02:32 -0500 Subject: [PATCH 59/78] Correct RR title regex --- lib/puppet/type/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 23a9e5b..165b8b0 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -22,11 +22,11 @@ title_patterns: [ { desc: 'full name, space, zone (explicitly defined), space, type, space, data', - pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?\w+) (?.*)$}, + pattern: %r{^(?.*?\.) (?[^ ]*\.) +(?\w+) (?.*)$}, }, { desc: 'full name, space, zone (explicitly defined), space, type', - pattern: %r{^(?.*?\.) (?.*[^ ]\.) +(?\w+)$}, + pattern: %r{^(?.*?\.) (?[^ ]*\.) +(?\w+)$}, }, { desc: 'name and zone (everything after the first dot)', From 6b6a2744ad3e778be86570c9b26a5a9a707dfcb0 Mon Sep 17 00:00:00 2001 From: griggi Date: Fri, 31 Dec 2021 01:57:32 -0500 Subject: [PATCH 60/78] add allow-recursion to bind options --- templates/etc/bind/named.conf.epp | 7 +++++++ types/options.pp | 1 + 2 files changed, 8 insertions(+) diff --git a/templates/etc/bind/named.conf.epp b/templates/etc/bind/named.conf.epp index 27aa0c3..e62220c 100644 --- a/templates/etc/bind/named.conf.epp +++ b/templates/etc/bind/named.conf.epp @@ -60,6 +60,13 @@ options { <%- } -%> }; <%- } -%> + <%- if $options['allow-recursion'] { -%> + allow-recursion { + <%- $options['allow-recursion'].each |$address_match_list_element| { -%> + <%= $address_match_list_element -%>; + <%- } -%> + }; + <%- } -%> <%- if $options['allow-update'] { -%> allow-update { <%- $options['allow-update'].each |$address_match_list_element| { -%> diff --git a/types/options.pp b/types/options.pp index c3a8b39..e768fff 100644 --- a/types/options.pp +++ b/types/options.pp @@ -7,6 +7,7 @@ type Bind::Options = Struct[{ Optional['allow-transfer'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['allow-update'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], + Optional['allow-recursion'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['allow-query'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['also-notify'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['auto-dnssec'] => Enum['allow', 'maintain', 'off'], From 7fb4ed261c5ffb9174f35fab06db8457761dd847 Mon Sep 17 00:00:00 2001 From: griggi Date: Fri, 31 Dec 2021 02:11:15 -0500 Subject: [PATCH 61/78] add allow-recursion to bind options --- templates/etc/bind/named.conf.epp | 4 ++-- types/options.pp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/etc/bind/named.conf.epp b/templates/etc/bind/named.conf.epp index e62220c..d56f823 100644 --- a/templates/etc/bind/named.conf.epp +++ b/templates/etc/bind/named.conf.epp @@ -60,9 +60,9 @@ options { <%- } -%> }; <%- } -%> - <%- if $options['allow-recursion'] { -%> + <%- if $options['allow_recursion'] { -%> allow-recursion { - <%- $options['allow-recursion'].each |$address_match_list_element| { -%> + <%- $options['allow_recursion'].each |$address_match_list_element| { -%> <%= $address_match_list_element -%>; <%- } -%> }; diff --git a/types/options.pp b/types/options.pp index e768fff..143ce0a 100644 --- a/types/options.pp +++ b/types/options.pp @@ -7,7 +7,7 @@ type Bind::Options = Struct[{ Optional['allow-transfer'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['allow-update'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], - Optional['allow-recursion'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], + Optional['allow_recursion'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['allow-query'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['also-notify'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], Optional['auto-dnssec'] => Enum['allow', 'maintain', 'off'], From f56d32e3ba35f6bdc19221ee5ebdbc89cbf516a5 Mon Sep 17 00:00:00 2001 From: griggi Date: Fri, 31 Dec 2021 02:50:58 -0500 Subject: [PATCH 62/78] add forward/forwarders to bind options --- templates/etc/bind/named.conf.epp | 10 ++++++++++ types/options.pp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/templates/etc/bind/named.conf.epp b/templates/etc/bind/named.conf.epp index d56f823..9d375ba 100644 --- a/templates/etc/bind/named.conf.epp +++ b/templates/etc/bind/named.conf.epp @@ -103,6 +103,16 @@ options { <%- if $options['zone-statistics'] { -%> zone-statistics <%= $options['zone-statistics'] %>; <%- } -%> + <%- if $options['forward'] { -%> + forward <%= $options['forward'] %>; + <%- } -%> + <%- if $options['forwarders'] { -%> + allow-query { + <%- $options['forwarders'].each |$address_match_list_element| { -%> + <%= $address_match_list_element -%>; + <%- } -%> + }; + <%- } -%> }; <%- } -%> diff --git a/types/options.pp b/types/options.pp index 143ce0a..55c3ac4 100644 --- a/types/options.pp +++ b/types/options.pp @@ -16,4 +16,6 @@ Optional['key-directory'] => String[1], Optional['serial-update-method'] => Enum['date', 'increment', 'unixtime'], Optional['zone-statistics'] => Variant[Boolean, Stdlib::Yes_no, Enum['full', 'terse', 'none']], + Optional['forward'] => Enum['first', 'only'], + Optional['forwarders'] => Array[Variant[Stdlib::Host, Stdlib::IP::Address]], }] From 972efb80f4b7fe90379f15bd4910f3521e57c1e1 Mon Sep 17 00:00:00 2001 From: griggi Date: Fri, 31 Dec 2021 03:45:25 -0500 Subject: [PATCH 63/78] add forward/forwarders to bind options --- templates/etc/bind/named.conf.epp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/etc/bind/named.conf.epp b/templates/etc/bind/named.conf.epp index 9d375ba..3257dd8 100644 --- a/templates/etc/bind/named.conf.epp +++ b/templates/etc/bind/named.conf.epp @@ -107,7 +107,7 @@ options { forward <%= $options['forward'] %>; <%- } -%> <%- if $options['forwarders'] { -%> - allow-query { + forwarders { <%- $options['forwarders'].each |$address_match_list_element| { -%> <%= $address_match_list_element -%>; <%- } -%> From af1e41fb0878c05aeed9e3cf18b053449598f1ad Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 12 Jan 2022 14:37:32 -0500 Subject: [PATCH 64/78] stop trimming quotes from record data --- .../provider/resource_record/resource_record.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 692105d..eaf3770 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -29,11 +29,11 @@ def get(context) context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] context.debug("RR type: #{rr[:type]}") - if line[4].respond_to?(:to_str) - rr[:data] = line[4].tr('\"', '') - else + #if line[4].respond_to?(:to_str) + # rr[:data] = line[4].tr('\"', '') + #else rr[:data] = line[4] - end + #end context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") @@ -48,7 +48,7 @@ def get(context) } end end - context.debug("#{records.inspect}") + #context.debug("#{records.inspect}") records end @@ -130,9 +130,9 @@ def canonicalize(_context, resources) if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end - if r[:data].respond_to?(:to_str) - r[:data] = r[:data].tr('\"', '') - end + #if r[:data].respond_to?(:to_str) + # r[:data] = r[:data].tr('\"', '') + #end end end end From 316dbf028a714d8b81daeb8f2756d1f846914aa6 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 12 Jan 2022 15:55:24 -0500 Subject: [PATCH 65/78] fixup for quoting TXT records --- .../resource_record/resource_record.rb | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index eaf3770..ea14b6b 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -29,11 +29,11 @@ def get(context) context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] context.debug("RR type: #{rr[:type]}") - #if line[4].respond_to?(:to_str) - # rr[:data] = line[4].tr('\"', '') - #else + if line[4].respond_to?(:to_str) + rr[:data] = line[4].tr('\"', '') + else rr[:data] = line[4] - #end + end context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") @@ -59,11 +59,19 @@ def create(context, name, should) #build a request for each managed zone on run, append all records we #need to act on, then send a bulk nsupdate for each zone #the delete line is temporary to prevent duplicate creations while this is in progress - cmd = "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" + if should[:type] == "TXT" + cmd = "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + cmd = "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. @@ -84,12 +92,21 @@ def create(context, name, should) def update(context, name, should) context.notice("Updating '#{name.inspect}' with #{should.inspect}") - cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" + if should[:type] == "TXT" + cmd = "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + cmd = "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) if should[:type] == "A" fqdn = should[:record] @@ -130,9 +147,9 @@ def canonicalize(_context, resources) if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end - #if r[:data].respond_to?(:to_str) - # r[:data] = r[:data].tr('\"', '') - #end + if r[:data].respond_to?(:to_str) + r[:data] = r[:data].tr('\"', '') + end end end end From 614846123bebe477be30b98f32012ae9addcc9e0 Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 19 Jan 2022 16:02:33 -0500 Subject: [PATCH 66/78] use instance variable for get akin to prefetch in legacy providers --- .../resource_record/resource_record.rb | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index ea14b6b..65adaa1 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -6,10 +6,8 @@ class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize system('rndc', 'dumpdb', '-zones') - end - def get(context) context.debug("Parsing dump for existing resource records...") - records = [] + @records = [] currentzone = "" #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| @@ -37,7 +35,7 @@ def get(context) context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' context.debug("RR zone: #{rr[:zone]}") - records << { + @records << { title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', record: "#{rr[:label]}", @@ -49,7 +47,10 @@ def get(context) end end #context.debug("#{records.inspect}") - records + + end + def get(context) + @records end def create(context, name, should) @@ -88,6 +89,15 @@ def create(context, name, should) ' | nsupdate -4 -l" system(cmd) end + @records << { + title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", + ensure: 'present', + record: "#{should[:record]}", + zone: "#{should[:zone]}", + type: "#{should[:type]}", + data: "#{should[:data]}", + ttl: "#{should[:ttl]}", + } end def update(context, name, should) @@ -123,6 +133,16 @@ def update(context, name, should) ' | nsupdate -4 -l" system(cmd) end + @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} + @records << { + title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", + ensure: 'present', + record: "#{should[:record]}", + zone: "#{should[:zone]}", + type: "#{should[:type]}", + data: "#{should[:data]}", + ttl: "#{should[:ttl]}", + } end def delete(context, name) @@ -133,6 +153,7 @@ def delete(context, name) quit ' | nsupdate -4 -l" system(cmd) + @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} end def canonicalize(_context, resources) From 20fba412b48a257ccaa93969126f49830371f0cb Mon Sep 17 00:00:00 2001 From: griggi Date: Wed, 19 Jan 2022 16:26:40 -0500 Subject: [PATCH 67/78] use instance variable for get akin to prefetch in legacy providers --- .../provider/resource_record/resource_record.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 65adaa1..5c4338b 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -6,7 +6,7 @@ class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize system('rndc', 'dumpdb', '-zones') - context.debug("Parsing dump for existing resource records...") + Puppet.debug("Parsing dump for existing resource records...") @records = [] currentzone = "" #FIXME: location varies based on config/OS @@ -14,27 +14,27 @@ def initialize if line[0] == ';' && line.length > 18 currentzone = line[/(?:.*?')(.*?)\//,1] if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase end - context.debug("current zone updated: #{currentzone}") + #context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase end - context.debug("----New RR---- label: #{rr[:label]}") + #context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] - context.debug("RR TTL: #{rr[:ttl]}") + #context.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] - context.debug("RR scope: #{rr[:scope]}") + #context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] - context.debug("RR type: #{rr[:type]}") + #context.debug("RR type: #{rr[:type]}") if line[4].respond_to?(:to_str) rr[:data] = line[4].tr('\"', '') else rr[:data] = line[4] end - context.debug("RR data: #{rr[:data]}") + #context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' - context.debug("RR zone: #{rr[:zone]}") + #context.debug("RR zone: #{rr[:zone]}") @records << { title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', From d5fe3e5d3aa500e9ba60aff03758c4f32a13618f Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Thu, 20 Jan 2022 09:03:20 -0500 Subject: [PATCH 68/78] make rubocop happy --- .devcontainer/devcontainer.json | 16 +- Rakefile | 1 + .../resource_record/resource_record.rb | 160 +++++++++--------- metadata.json | 6 +- 4 files changed, 89 insertions(+), 94 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f1a55dc..fe7a8b1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,23 +1,17 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet { "name": "Puppet Development Kit (Community)", "dockerFile": "Dockerfile", - // Set *default* container specific settings.json values on container create. "settings": { - "terminal.integrated.shell.linux": "/bin/bash" + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash", + } + } }, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "puppet.puppet-vscode", "rebornix.Ruby" ] - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "pdk --version", } diff --git a/Rakefile b/Rakefile index 3f2ab9a..7d111bf 100644 --- a/Rakefile +++ b/Rakefile @@ -43,6 +43,7 @@ end PuppetLint.configuration.send('disable_relative') + if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 5c4338b..4372cf8 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,81 +5,81 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize + super() system('rndc', 'dumpdb', '-zones') - Puppet.debug("Parsing dump for existing resource records...") + Puppet.debug('Parsing dump for existing resource records...') @records = [] - currentzone = "" - #FIXME: location varies based on config/OS + currentzone = '' + # FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - currentzone = line[/(?:.*?')(.*?)\//,1] + currentzone = line[%r{(?:.*?')(.*?)\/}, 1] if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase end - #context.debug("current zone updated: #{currentzone}") + # Puppet.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase end - #context.debug("----New RR---- label: #{rr[:label]}") + # Puppet.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] - #context.debug("RR TTL: #{rr[:ttl]}") + # Puppet.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] - #context.debug("RR scope: #{rr[:scope]}") + # Puppet.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] - #context.debug("RR type: #{rr[:type]}") - if line[4].respond_to?(:to_str) - rr[:data] = line[4].tr('\"', '') - else - rr[:data] = line[4] - end - #context.debug("RR data: #{rr[:data]}") + # Puppet.debug("RR type: #{rr[:type]}") + rr[:data] = if line[4].respond_to?(:to_str) + line[4].tr('\"', '') + else + line[4] + end + # context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' - #context.debug("RR zone: #{rr[:zone]}") + # context.debug("RR zone: #{rr[:zone]}") @records << { title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', - record: "#{rr[:label]}", - zone: "#{rr[:zone]}", - type: "#{rr[:type]}", - data: "#{rr[:data]}", - ttl: "#{rr[:ttl]}", + record: rr[:label].to_s, + zone: rr[:zone].to_s, + type: rr[:type].to_s, + data: rr[:data].to_s, + ttl: rr[:ttl].to_s, } end end - #context.debug("#{records.inspect}") - + # context.debug("#{records.inspect}") end - def get(context) + + def get(_context) @records end def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") - #I dislike having to send an individual nsupdate for each record, it'd be preferable to - #build a request for each managed zone on run, append all records we - #need to act on, then send a bulk nsupdate for each zone - #the delete line is temporary to prevent duplicate creations while this is in progress - if should[:type] == "TXT" - cmd = "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - cmd = "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + # I dislike having to send an individual nsupdate for each record, it'd be preferable to + # build a request for each managed zone on run, append all records we + # need to act on, then send a bulk nsupdate for each zone - this would require a legacy provider's flush operation + cmd = if should[:type] == 'TXT' + "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - - #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. - if should[:type] == "A" + + # FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. + if should[:type] == 'A' fqdn = should[:record] - if fqdn[fqdn.length-1] != "." - fqdn = fqdn + should[:zone] + if fqdn[fqdn.length - 1] != '.' + fqdn += should[:zone] end reverse = IPAddr.new(should[:data]).reverse cmd = "echo 'update delete #{reverse} PTR @@ -92,36 +92,36 @@ def create(context, name, should) @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: "#{should[:record]}", - zone: "#{should[:zone]}", - type: "#{should[:type]}", - data: "#{should[:data]}", - ttl: "#{should[:ttl]}", + record: should[:record].to_s, + zone: should[:zone].to_s, + type: should[:type].to_s, + data: should[:data].to_s, + ttl: should[:ttl].to_s, } end def update(context, name, should) context.notice("Updating '#{name.inspect}' with #{should.inspect}") - if should[:type] == "TXT" - cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + cmd = if should[:type] == 'TXT' + "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - if should[:type] == "A" + if should[:type] == 'A' fqdn = should[:record] - if fqdn[fqdn.length-1] != "." - fqdn = fqdn + should[:zone] + if fqdn[fqdn.length - 1] != '.' + fqdn += should[:zone] end reverse = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") @@ -133,17 +133,17 @@ def update(context, name, should) ' | nsupdate -4 -l" system(cmd) end - @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} + @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: "#{should[:record]}", - zone: "#{should[:zone]}", - type: "#{should[:type]}", - data: "#{should[:data]}", - ttl: "#{should[:ttl]}", + record: should[:record].to_s, + zone: should[:zone].to_s, + type: should[:type].to_s, + data: should[:data].to_s, + ttl: should[:ttl].to_s, } - end + end def delete(context, name) context.notice("Deleting '#{name}'") @@ -153,19 +153,19 @@ def delete(context, name) quit ' | nsupdate -4 -l" system(cmd) - @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} + @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } end - def canonicalize(_context, resources) + def canonicalize(context, resources) resources.each do |r| - _context.debug("#{r.inspect}") + context.debug(r.inspect) if r[:record].respond_to?(:to_str) r[:record] = r[:record].downcase.strip end if r[:zone].respond_to?(:to_str) r[:zone] = r[:zone].downcase end - if r[:type].respond_to?(:to_str) + if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end if r[:data].respond_to?(:to_str) diff --git a/metadata.json b/metadata.json index 91c89cc..c7dd6e5 100644 --- a/metadata.json +++ b/metadata.json @@ -50,9 +50,9 @@ "version_requirement": ">= 6.1.0 < 8.0.0" } ], - "pdk-version": "2.2.0", - "template-url": "pdk-default#2.2.0", - "template-ref": "tags/2.2.0-0-g2381db6", + "pdk-version": "2.3.0", + "template-url": "pdk-default#2.3.0", + "template-ref": "tags/2.3.0-0-g8aaceff", "tags": [ "bind", "bind9", From b526c9775b624a6d2b5a0d501974ed850274aa71 Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Mon, 28 Feb 2022 15:02:55 -0500 Subject: [PATCH 69/78] make rubocop happy --- lib/puppet/provider/resource_record/resource_record.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 4372cf8..7644cb1 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -11,6 +11,9 @@ def initialize @records = [] currentzone = '' # FIXME: location varies based on config/OS + unless File.exist?('/var/cache/bind/named_dump.db') + raise Puppet::Error, 'The named dump file does not exist in the expected location, cannot continue.' + end File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 currentzone = line[%r{(?:.*?')(.*?)\/}, 1] From 8e72186a1a3b9af3496849c60bf2aff87f3651f9 Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Mon, 28 Feb 2022 15:34:07 -0500 Subject: [PATCH 70/78] add provisions for a flag that prevents automatic PTR overwrites --- .../provider/resource_record/resource_record.rb | 11 +++++++++-- lib/puppet/type/resource_record.rb | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 7644cb1..0794847 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -9,6 +9,7 @@ def initialize system('rndc', 'dumpdb', '-zones') Puppet.debug('Parsing dump for existing resource records...') @records = [] + @heldptr = [] currentzone = '' # FIXME: location varies based on config/OS unless File.exist?('/var/cache/bind/named_dump.db') @@ -79,7 +80,10 @@ def create(context, name, should) system(cmd) # FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. - if should[:type] == 'A' + if (should[:type] == 'A') && !(@heldptr.key? should[:record]) + if should[:holdptr] + @heldptr[should[:record]] = should[:holdptr] + end fqdn = should[:record] if fqdn[fqdn.length - 1] != '.' fqdn += should[:zone] @@ -121,7 +125,10 @@ def update(context, name, should) ' | nsupdate -4 -l" end system(cmd) - if should[:type] == 'A' + if (should[:type] == 'A') && !(@heldptr.key? should[:record]) + if should[:holdptr] + @heldptr[should[:record]] = should[:holdptr] + end fqdn = should[:record] if fqdn[fqdn.length - 1] != '.' fqdn += should[:zone] diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 165b8b0..4fa1bf5 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -47,6 +47,12 @@ desc: 'Whether this resource record should be present or absent on the target system.', default: 'present', }, + ptrhold: { + type: 'Boolean', + desc: 'Make this record the only one used for an accompanying reverse record.', + behavior: :parameter, + default: false, + }, record: { type: 'String', desc: 'The name of the resource record, also known as the owner or label.', From 330bbc87934570609500df5a21b00958eb703ec4 Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Mon, 28 Feb 2022 15:38:23 -0500 Subject: [PATCH 71/78] add provisions for a flag that prevents automatic PTR overwrites --- lib/puppet/provider/resource_record/resource_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 0794847..e27118e 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -81,7 +81,7 @@ def create(context, name, should) # FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. if (should[:type] == 'A') && !(@heldptr.key? should[:record]) - if should[:holdptr] + if should[:holdptr] == 'true' @heldptr[should[:record]] = should[:holdptr] end fqdn = should[:record] @@ -126,7 +126,7 @@ def update(context, name, should) end system(cmd) if (should[:type] == 'A') && !(@heldptr.key? should[:record]) - if should[:holdptr] + if should[:holdptr] == 'true' @heldptr[should[:record]] = should[:holdptr] end fqdn = should[:record] From 6d38074ff1ca296e5a12173bdde6758c7f07c76e Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Tue, 1 Mar 2022 08:23:00 -0500 Subject: [PATCH 72/78] add provisions for a flag that prevents automatic PTR overwrites --- lib/puppet/provider/resource_record/resource_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index e27118e..32ee1f8 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -9,7 +9,7 @@ def initialize system('rndc', 'dumpdb', '-zones') Puppet.debug('Parsing dump for existing resource records...') @records = [] - @heldptr = [] + @heldptr = {} currentzone = '' # FIXME: location varies based on config/OS unless File.exist?('/var/cache/bind/named_dump.db') From 100461f1a854636b74e940ebbb60585ceff6ce2a Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Fri, 4 Mar 2022 10:35:00 -0500 Subject: [PATCH 73/78] add provisions for a flag that prevents automatic PTR overwrites --- lib/puppet/type/resource_record.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 4fa1bf5..0073fd4 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -50,7 +50,6 @@ ptrhold: { type: 'Boolean', desc: 'Make this record the only one used for an accompanying reverse record.', - behavior: :parameter, default: false, }, record: { From 5cc23ea84da04461d2a580ab28da6774f2cf7629 Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Fri, 4 Mar 2022 10:49:22 -0500 Subject: [PATCH 74/78] Revert "add provisions for a flag that prevents automatic PTR overwrites" This reverts commit 100461f1a854636b74e940ebbb60585ceff6ce2a. --- lib/puppet/type/resource_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 0073fd4..4fa1bf5 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -50,6 +50,7 @@ ptrhold: { type: 'Boolean', desc: 'Make this record the only one used for an accompanying reverse record.', + behavior: :parameter, default: false, }, record: { From 4ab0ee1a9ee999e735783d17e896a1ac8bbc5fc7 Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Tue, 8 Mar 2022 09:24:45 -0500 Subject: [PATCH 75/78] force an initialize call if get has no results --- lib/puppet/provider/resource_record/resource_record.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 32ee1f8..23d90ce 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -55,6 +55,9 @@ def initialize end def get(_context) + if @records.empty? + initialize + end @records end From 85fb4c7d5b9ea835f3f67a6fde3c4157f3fe5e8a Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Tue, 8 Mar 2022 09:29:35 -0500 Subject: [PATCH 76/78] add some debug prints --- lib/puppet/provider/resource_record/resource_record.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 23d90ce..aa02b1a 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -54,7 +54,8 @@ def initialize # context.debug("#{records.inspect}") end - def get(_context) + def get(context) + Puppet.debug("get called, context: #{context}") if @records.empty? initialize end @@ -62,6 +63,7 @@ def get(_context) end def create(context, name, should) + Puppet.debug("create called, context: #{context}") context.notice("Creating '#{name}' with #{should.inspect}") # I dislike having to send an individual nsupdate for each record, it'd be preferable to @@ -111,6 +113,7 @@ def create(context, name, should) end def update(context, name, should) + Puppet.debug("update called, context: #{context}") context.notice("Updating '#{name.inspect}' with #{should.inspect}") cmd = if should[:type] == 'TXT' "echo 'zone #{should[:zone]} @@ -159,6 +162,7 @@ def update(context, name, should) end def delete(context, name) + Puppet.debug("delete called, context: #{context}") context.notice("Deleting '#{name}'") cmd = "echo 'zone #{name[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} @@ -170,6 +174,7 @@ def delete(context, name) end def canonicalize(context, resources) + Puppet.debug("canonicalize called, context: #{context}") resources.each do |r| context.debug(r.inspect) if r[:record].respond_to?(:to_str) From 22e9a05c74a8679a5b33396d6082f0406e33c792 Mon Sep 17 00:00:00 2001 From: griggi-clarkson <79097462+griggi-clarkson@users.noreply.github.com> Date: Wed, 6 Apr 2022 08:43:19 -0400 Subject: [PATCH 77/78] Revert "Add 'ptrhold' parameter for finer control over automatic PTR generation" --- .devcontainer/devcontainer.json | 16 +- Rakefile | 1 - .../resource_record/resource_record.rb | 176 ++++++++---------- lib/puppet/type/resource_record.rb | 6 - metadata.json | 6 +- 5 files changed, 93 insertions(+), 112 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fe7a8b1..f1a55dc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,17 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet { "name": "Puppet Development Kit (Community)", "dockerFile": "Dockerfile", + // Set *default* container specific settings.json values on container create. "settings": { - "terminal.integrated.profiles.linux": { - "bash": { - "path": "bash", - } - } + "terminal.integrated.shell.linux": "/bin/bash" }, + // Add the IDs of extensions you want installed when the container is created. "extensions": [ "puppet.puppet-vscode", "rebornix.Ruby" ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pdk --version", } diff --git a/Rakefile b/Rakefile index 7d111bf..3f2ab9a 100644 --- a/Rakefile +++ b/Rakefile @@ -43,7 +43,6 @@ end PuppetLint.configuration.send('disable_relative') - if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index aa02b1a..5c4338b 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,93 +5,81 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize - super() system('rndc', 'dumpdb', '-zones') - Puppet.debug('Parsing dump for existing resource records...') + Puppet.debug("Parsing dump for existing resource records...") @records = [] - @heldptr = {} - currentzone = '' - # FIXME: location varies based on config/OS - unless File.exist?('/var/cache/bind/named_dump.db') - raise Puppet::Error, 'The named dump file does not exist in the expected location, cannot continue.' - end + currentzone = "" + #FIXME: location varies based on config/OS File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - currentzone = line[%r{(?:.*?')(.*?)\/}, 1] + currentzone = line[/(?:.*?')(.*?)\//,1] if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase end - # Puppet.debug("current zone updated: #{currentzone}") + #context.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase end - # Puppet.debug("----New RR---- label: #{rr[:label]}") + #context.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] - # Puppet.debug("RR TTL: #{rr[:ttl]}") + #context.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] - # Puppet.debug("RR scope: #{rr[:scope]}") + #context.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] - # Puppet.debug("RR type: #{rr[:type]}") - rr[:data] = if line[4].respond_to?(:to_str) - line[4].tr('\"', '') - else - line[4] - end - # context.debug("RR data: #{rr[:data]}") + #context.debug("RR type: #{rr[:type]}") + if line[4].respond_to?(:to_str) + rr[:data] = line[4].tr('\"', '') + else + rr[:data] = line[4] + end + #context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' - # context.debug("RR zone: #{rr[:zone]}") + #context.debug("RR zone: #{rr[:zone]}") @records << { title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', - record: rr[:label].to_s, - zone: rr[:zone].to_s, - type: rr[:type].to_s, - data: rr[:data].to_s, - ttl: rr[:ttl].to_s, + record: "#{rr[:label]}", + zone: "#{rr[:zone]}", + type: "#{rr[:type]}", + data: "#{rr[:data]}", + ttl: "#{rr[:ttl]}", } end end - # context.debug("#{records.inspect}") + #context.debug("#{records.inspect}") + end - def get(context) - Puppet.debug("get called, context: #{context}") - if @records.empty? - initialize - end @records end def create(context, name, should) - Puppet.debug("create called, context: #{context}") context.notice("Creating '#{name}' with #{should.inspect}") - # I dislike having to send an individual nsupdate for each record, it'd be preferable to - # build a request for each managed zone on run, append all records we - # need to act on, then send a bulk nsupdate for each zone - this would require a legacy provider's flush operation - cmd = if should[:type] == 'TXT' - "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + #I dislike having to send an individual nsupdate for each record, it'd be preferable to + #build a request for each managed zone on run, append all records we + #need to act on, then send a bulk nsupdate for each zone + #the delete line is temporary to prevent duplicate creations while this is in progress + if should[:type] == "TXT" + cmd = "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + cmd = "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - - # FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. - if (should[:type] == 'A') && !(@heldptr.key? should[:record]) - if should[:holdptr] == 'true' - @heldptr[should[:record]] = should[:holdptr] - end + + #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. + if should[:type] == "A" fqdn = should[:record] - if fqdn[fqdn.length - 1] != '.' - fqdn += should[:zone] + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] end reverse = IPAddr.new(should[:data]).reverse cmd = "echo 'update delete #{reverse} PTR @@ -104,40 +92,36 @@ def create(context, name, should) @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: should[:record].to_s, - zone: should[:zone].to_s, - type: should[:type].to_s, - data: should[:data].to_s, - ttl: should[:ttl].to_s, + record: "#{should[:record]}", + zone: "#{should[:zone]}", + type: "#{should[:type]}", + data: "#{should[:data]}", + ttl: "#{should[:ttl]}", } end def update(context, name, should) - Puppet.debug("update called, context: #{context}") context.notice("Updating '#{name.inspect}' with #{should.inspect}") - cmd = if should[:type] == 'TXT' - "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + if should[:type] == "TXT" + cmd = "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + cmd = "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - if (should[:type] == 'A') && !(@heldptr.key? should[:record]) - if should[:holdptr] == 'true' - @heldptr[should[:record]] = should[:holdptr] - end + if should[:type] == "A" fqdn = should[:record] - if fqdn[fqdn.length - 1] != '.' - fqdn += should[:zone] + if fqdn[fqdn.length-1] != "." + fqdn = fqdn + should[:zone] end reverse = IPAddr.new(should[:data]).reverse context.debug("fqdn: #{fqdn}") @@ -149,20 +133,19 @@ def update(context, name, should) ' | nsupdate -4 -l" system(cmd) end - @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } + @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: should[:record].to_s, - zone: should[:zone].to_s, - type: should[:type].to_s, - data: should[:data].to_s, - ttl: should[:ttl].to_s, + record: "#{should[:record]}", + zone: "#{should[:zone]}", + type: "#{should[:type]}", + data: "#{should[:data]}", + ttl: "#{should[:ttl]}", } - end + end def delete(context, name) - Puppet.debug("delete called, context: #{context}") context.notice("Deleting '#{name}'") cmd = "echo 'zone #{name[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} @@ -170,20 +153,19 @@ def delete(context, name) quit ' | nsupdate -4 -l" system(cmd) - @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } + @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} end - def canonicalize(context, resources) - Puppet.debug("canonicalize called, context: #{context}") + def canonicalize(_context, resources) resources.each do |r| - context.debug(r.inspect) + _context.debug("#{r.inspect}") if r[:record].respond_to?(:to_str) r[:record] = r[:record].downcase.strip end if r[:zone].respond_to?(:to_str) r[:zone] = r[:zone].downcase end - if r[:type].respond_to?(:to_str) + if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end if r[:data].respond_to?(:to_str) diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 4fa1bf5..165b8b0 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -47,12 +47,6 @@ desc: 'Whether this resource record should be present or absent on the target system.', default: 'present', }, - ptrhold: { - type: 'Boolean', - desc: 'Make this record the only one used for an accompanying reverse record.', - behavior: :parameter, - default: false, - }, record: { type: 'String', desc: 'The name of the resource record, also known as the owner or label.', diff --git a/metadata.json b/metadata.json index c7dd6e5..91c89cc 100644 --- a/metadata.json +++ b/metadata.json @@ -50,9 +50,9 @@ "version_requirement": ">= 6.1.0 < 8.0.0" } ], - "pdk-version": "2.3.0", - "template-url": "pdk-default#2.3.0", - "template-ref": "tags/2.3.0-0-g8aaceff", + "pdk-version": "2.2.0", + "template-url": "pdk-default#2.2.0", + "template-ref": "tags/2.2.0-0-g2381db6", "tags": [ "bind", "bind9", From 2b0764564a3d200b07046d16c1a22aa2eee28e0d Mon Sep 17 00:00:00 2001 From: Gavin Riggi Date: Thu, 2 Jun 2022 15:36:22 -0400 Subject: [PATCH 78/78] resolve merge conflicts --- .../resource_record/resource_record.rb | 220 ++++++++++-------- lib/puppet/type/resource_record.rb | 6 + manifests/install.pp | 21 -- spec/classes/bind_spec.rb | 22 -- 4 files changed, 129 insertions(+), 140 deletions(-) diff --git a/lib/puppet/provider/resource_record/resource_record.rb b/lib/puppet/provider/resource_record/resource_record.rb index 5c4338b..fb08f42 100644 --- a/lib/puppet/provider/resource_record/resource_record.rb +++ b/lib/puppet/provider/resource_record/resource_record.rb @@ -5,147 +5,172 @@ # Implementation for the resource_record type using the Resource API. class Puppet::Provider::ResourceRecord::ResourceRecord < Puppet::ResourceApi::SimpleProvider def initialize + super() system('rndc', 'dumpdb', '-zones') - Puppet.debug("Parsing dump for existing resource records...") + # Have to wait to ensure file is actually populated...embarrassingly this was the source of much wheel spinning. + sleep(2) + Puppet.debug('Parsing dump for existing resource records...') @records = [] - currentzone = "" - #FIXME: location varies based on config/OS + @heldptr = {} + currentzone = '' + # FIXME: location varies based on config/OS + unless File.exist?('/var/cache/bind/named_dump.db') + raise Puppet::Error, 'The named dump file does not exist in the expected location, cannot continue.' + end File.readlines('/var/cache/bind/named_dump.db').each do |line| if line[0] == ';' && line.length > 18 - currentzone = line[/(?:.*?')(.*?)\//,1] + currentzone = line[%r{(?:.*?')(.*?)\/}, 1] if currentzone.respond_to?(:to_str); currentzone = currentzone.downcase end - #context.debug("current zone updated: #{currentzone}") + Puppet.debug("current zone updated: #{currentzone}") elsif line[0] != ';' line = line.strip.split(' ', 5) rr = {} rr[:label] = line[0] if rr[:label].respond_to?(:to_str); rr[:label] = rr[:label].downcase end - #context.debug("----New RR---- label: #{rr[:label]}") + # Puppet.debug("----New RR---- label: #{rr[:label]}") rr[:ttl] = line[1] - #context.debug("RR TTL: #{rr[:ttl]}") + # Puppet.debug("RR TTL: #{rr[:ttl]}") rr[:scope] = line[2] - #context.debug("RR scope: #{rr[:scope]}") + # Puppet.debug("RR scope: #{rr[:scope]}") rr[:type] = line[3] - #context.debug("RR type: #{rr[:type]}") - if line[4].respond_to?(:to_str) - rr[:data] = line[4].tr('\"', '') - else - rr[:data] = line[4] - end - #context.debug("RR data: #{rr[:data]}") + # Puppet.debug("RR type: #{rr[:type]}") + rr[:data] = if line[4].respond_to?(:to_str) + line[4].tr('\"', '') + else + line[4] + end + # context.debug("RR data: #{rr[:data]}") rr[:zone] = currentzone + '.' - #context.debug("RR zone: #{rr[:zone]}") + # context.debug("RR zone: #{rr[:zone]}") @records << { title: "#{rr[:label]} #{rr[:zone]} #{rr[:type]} #{rr[:data]}", ensure: 'present', - record: "#{rr[:label]}", - zone: "#{rr[:zone]}", - type: "#{rr[:type]}", - data: "#{rr[:data]}", - ttl: "#{rr[:ttl]}", + record: rr[:label].to_s, + zone: rr[:zone].to_s, + type: rr[:type].to_s, + data: rr[:data].to_s, + ttl: rr[:ttl].to_s, } end end - #context.debug("#{records.inspect}") - + # context.debug("#{records.inspect}") end + def get(context) + Puppet.debug("get called, context: #{context}") + if @records.empty? + initialize + end @records end def create(context, name, should) + Puppet.debug("create called, context: #{context}") context.notice("Creating '#{name}' with #{should.inspect}") - #I dislike having to send an individual nsupdate for each record, it'd be preferable to - #build a request for each managed zone on run, append all records we - #need to act on, then send a bulk nsupdate for each zone - #the delete line is temporary to prevent duplicate creations while this is in progress - if should[:type] == "TXT" - cmd = "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - cmd = "echo 'zone #{should[:zone]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + # I dislike having to send an individual nsupdate for each record, it'd be preferable to + # build a request for each managed zone on run, append all records we + # need to act on, then send a bulk nsupdate for each zone - this would require a legacy provider's flush operation + cmd = if should[:type] == 'TXT' + "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + "echo 'zone #{should[:zone]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - - #FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. - if should[:type] == "A" - fqdn = should[:record] - if fqdn[fqdn.length-1] != "." - fqdn = fqdn + should[:zone] + + # FIXME: This will generate PTR records, but assumes the arpa zones are preexisting. + if should[:type] == 'A' + unless @heldptr.key? should[:data].to_sym + if should[:ptrhold] + context.debug("Adding sticky PTR entry for #{should[:data]}->#{should[:record]}") + @heldptr[should[:data].to_sym] = should[:record] + end + fqdn = should[:record] + if fqdn[fqdn.length - 1] != '.' + fqdn += should[:zone] + end + reverse = IPAddr.new(should[:data]).reverse + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} #{should[:ttl]} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) end - reverse = IPAddr.new(should[:data]).reverse - cmd = "echo 'update delete #{reverse} PTR - update add #{reverse} #{should[:ttl]} PTR #{fqdn} - send - quit - ' | nsupdate -4 -l" - system(cmd) end @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: "#{should[:record]}", - zone: "#{should[:zone]}", - type: "#{should[:type]}", - data: "#{should[:data]}", - ttl: "#{should[:ttl]}", + record: should[:record].to_s, + zone: should[:zone].to_s, + type: should[:type].to_s, + data: should[:data].to_s, + ttl: should[:ttl].to_s, } end def update(context, name, should) + Puppet.debug("update called, context: #{context}") context.notice("Updating '#{name.inspect}' with #{should.inspect}") - if should[:type] == "TXT" - cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" - send - quit - ' | nsupdate -4 -l" - else - cmd = "echo 'zone #{should[:zone]} - update delete #{name[:record]} #{name[:type]} #{name[:data]} - update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} - send - quit - ' | nsupdate -4 -l" - end + cmd = if should[:type] == 'TXT' + "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} \"#{should[:data]}\" + send + quit + ' | nsupdate -4 -l" + else + "echo 'zone #{should[:zone]} + update delete #{name[:record]} #{name[:type]} #{name[:data]} + update add #{should[:record]} #{should[:ttl]} #{should[:type]} #{should[:data]} + send + quit + ' | nsupdate -4 -l" + end system(cmd) - if should[:type] == "A" - fqdn = should[:record] - if fqdn[fqdn.length-1] != "." - fqdn = fqdn + should[:zone] + if should[:type] == 'A' + unless @heldptr.key? should[:data].to_sym + if should[:ptrhold] + context.debug("Adding sticky PTR entry for #{should[:data]}->#{should[:record]}") + @heldptr[should[:data].to_sym] = should[:record] + end + fqdn = should[:record] + if fqdn[fqdn.length - 1] != '.' + fqdn += should[:zone] + end + reverse = IPAddr.new(should[:data]).reverse + context.debug("fqdn: #{fqdn}") + context.debug("reverse: #{reverse}") + cmd = "echo 'update delete #{reverse} PTR + update add #{reverse} #{should[:ttl]} PTR #{fqdn} + send + quit + ' | nsupdate -4 -l" + system(cmd) end - reverse = IPAddr.new(should[:data]).reverse - context.debug("fqdn: #{fqdn}") - context.debug("reverse: #{reverse}") - cmd = "echo 'update delete #{reverse} PTR - update add #{reverse} #{should[:ttl]} PTR #{fqdn} - send - quit - ' | nsupdate -4 -l" - system(cmd) end - @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} + @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } @records << { title: "#{should[:record]} #{should[:zone]} #{should[:type]} #{should[:data]}", ensure: 'present', - record: "#{should[:record]}", - zone: "#{should[:zone]}", - type: "#{should[:type]}", - data: "#{should[:data]}", - ttl: "#{should[:ttl]}", + record: should[:record].to_s, + zone: should[:zone].to_s, + type: should[:type].to_s, + data: should[:data].to_s, + ttl: should[:ttl].to_s, } - end + end def delete(context, name) + Puppet.debug("delete called, context: #{context}") context.notice("Deleting '#{name}'") cmd = "echo 'zone #{name[:zone]} update delete #{name[:record]} #{name[:type]} #{name[:data]} @@ -153,19 +178,20 @@ def delete(context, name) quit ' | nsupdate -4 -l" system(cmd) - @records.reject! {|rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}"} + @records.reject! { |rr| rr[:title] == "#{name[:record]} #{name[:zone]} #{name[:type]} #{name[:data]}" } end - def canonicalize(_context, resources) + def canonicalize(context, resources) + Puppet.debug("canonicalize called, context: #{context}") resources.each do |r| - _context.debug("#{r.inspect}") + context.debug(r.inspect) if r[:record].respond_to?(:to_str) r[:record] = r[:record].downcase.strip end if r[:zone].respond_to?(:to_str) r[:zone] = r[:zone].downcase end - if r[:type].respond_to?(:to_str) + if r[:type].respond_to?(:to_str) r[:type] = r[:type].upcase end if r[:data].respond_to?(:to_str) diff --git a/lib/puppet/type/resource_record.rb b/lib/puppet/type/resource_record.rb index 165b8b0..4fa1bf5 100644 --- a/lib/puppet/type/resource_record.rb +++ b/lib/puppet/type/resource_record.rb @@ -47,6 +47,12 @@ desc: 'Whether this resource record should be present or absent on the target system.', default: 'present', }, + ptrhold: { + type: 'Boolean', + desc: 'Make this record the only one used for an accompanying reverse record.', + behavior: :parameter, + default: false, + }, record: { type: 'String', desc: 'The name of the resource record, also known as the owner or label.', diff --git a/manifests/install.pp b/manifests/install.pp index 6b527ee..21f3f25 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -7,27 +7,6 @@ class bind::install { assert_private() - if $bind::authoritative { - ensure_packages( - [ - 'g++', - 'make', - ], - { - ensure => installed, - before => Package['dnsruby'], - }, - ) - - ensure_packages( - 'dnsruby', - { - ensure => installed, - provider => puppet_gem, - }, - ) - } - if $bind::package_backport { require apt::backports } diff --git a/spec/classes/bind_spec.rb b/spec/classes/bind_spec.rb index a10c4b7..d7ad6ed 100644 --- a/spec/classes/bind_spec.rb +++ b/spec/classes/bind_spec.rb @@ -217,28 +217,6 @@ end it { is_expected.to compile.with_all_deps } - - # dnsruby build dependencies - if os_facts[:os]['name'] == 'Debian' - [ - 'g++', - 'make', - ].each do |pkg| - it do - is_expected.to contain_package(pkg).with( - ensure: 'installed', - before: 'Package[dnsruby]', - ) - end - end - end - - it do - is_expected.to contain_package('dnsruby').with( - ensure: 'installed', - provider: 'puppet_gem', - ) - end end context 'with dev packages' do