Skip to content

Changes and improvements so the recipe works on Ubuntu 14.04 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'zonefile'
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
default[:bind9][:data_path] = "/var/cache/bind"
default[:bind9][:user] = "bind"
end
default[:bind9][:serial_number] = 0
45 changes: 45 additions & 0 deletions bin/zonefile_to_databag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env ruby
require 'zonefile'
require 'optparse'

options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: zonefile_to_databag.rb [options]"

opts.on("-z", "--zonefile FILE", "Parse Zone File") do |v|
options[:zonefile] = v
end
end

begin
optparse.parse!
if options[:zonefile].nil?
puts optparse
raise OptionParser::MissingArgument
end
end


zf = Zonefile.from_file(options[:zonefile])
puts '; MX-Records'
zf.mx.each do |mx_record|
puts "Mail Exchagne with priority: #{mx_record[:pri]} --> #{mx_record[:host]}"
end

# Show SOA TTL
puts "; Record Time To Live: #{zf.soa[:ttl]}"

# Show A-Records
puts "; A Records:"
zf.a.each do |a_record|
ttl_text = ''
if !a_record[:ttl].nil? and a_record[:ttl] != '' and a_record[:ttl] != zf.ttl
ttl_text = "\"ttl\": \"#{a_record[:ttl]}\", "
end
puts "{ \"type\": \"A\", #{ttl_text}\"name\": \"#{a_record[:name]}\", \"ip\": \"#{a_record[:host]}\"},"
end

puts "; CNAME Records:"
zf.cname.each do |cname_record|
puts "{ \"type\": \"CNAME\" , \"name\": \"#{cname_record[:name]}\", \"ip\": \"#{cname_record[:host]}\"},"
end
3 changes: 2 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name "bind9"
maintainer "Mike Adolphs"
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs/Configures bind9"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.9"
version "0.1.10"

%w{ ubuntu debian centos }.each do |os|
supports os
Expand Down
22 changes: 19 additions & 3 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
action :install
end

directory "/var/log/bind/" do
directory "/var/log/named/" do
owner node[:bind9][:user]
group node[:bind9][:user]
mode 0755
Expand Down Expand Up @@ -62,7 +62,8 @@

search(:zones).each do |zone|
unless zone['autodomain'].nil? || zone['autodomain'] == ''
search(:node, "domain:#{zone['autodomain']}").each do |host|
log "fqdn:*.#{zone['autodomain']}"
search(:node, "fqdn:*.#{zone['autodomain']}").each do |host|
next if host['ipaddress'] == '' || host['ipaddress'].nil?
zone['zone_info']['records'].push( {
"name" => host['hostname'],
Expand All @@ -72,6 +73,19 @@
end
end

# This cookbook documents yyyyMMddNN but attempts yyyyMMddhhmmss which is too long for BIND. Instead, let's wrap a 2 digit serial number in to the last 2 NN digits.
ruby_block "increment_serial_number" do
block do
current = node[:bind9][:serial_number].to_i + 1
if current > 99
current = 0
end
node.set[:bind9][:serial_number] = current
end
action :nothing
end


template "#{node[:bind9][:config_path]}/#{zone['domain']}" do
source "#{node[:bind9][:config_path]}/#{zone['domain']}.erb"
local true
Expand All @@ -80,7 +94,7 @@
mode 0644
notifies :restart, resources(:service => "bind9")
variables({
:serial => Time.new.strftime("%Y%m%d%H%M%S")
:serial => Time.new.strftime("%Y%m%d") + node[:bind9][:serial_number].to_s.rjust(2, "0")
})
action :nothing
end
Expand All @@ -93,12 +107,14 @@
variables({
:domain => zone['domain'],
:soa => zone['zone_info']['soa'],
:soa_apex => zone['zone_info'].has_key?('soa_apex') ? zone['zone_info']['soa_apex'] : '@',
:contact => zone['zone_info']['contact'],
:global_ttl => zone['zone_info']['global_ttl'],
:nameserver => zone['zone_info']['nameserver'],
:mail_exchange => zone['zone_info']['mail_exchange'],
:records => zone['zone_info']['records']
})
notifies :run, resources(:ruby_block => "increment_serial_number"), :immediately
notifies :create, resources(:template => "#{node[:bind9][:config_path]}/#{zone['domain']}"), :immediately
end
end
Expand Down
5 changes: 4 additions & 1 deletion templates/default/named.conf.options.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ options {
<% if node[:bind9][:enable_ipv6] %>
listen-on-v6 { any; };
<% end %>

transfer-format many-answers;
};

logging {
channel default_log {
file "/var/log/bind/bind.log" versions 5 size 128M;
file "/var/log/named/bind.log" versions 5 size 128M;
print-time yes;
print-severity yes;
print-category yes;
};

category default { default_log; };
category general { default_log; };
category lame-servers { null; };
};
2 changes: 1 addition & 1 deletion templates/default/zonefile.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$TTL <%= @global_ttl %>
@ IN SOA <%= @soa %> <%= @contact %> (
<%= @soa_apex %> IN SOA <%= @soa %> <%= @contact %> (
<%%= @serial %> ; serial [yyyyMMddNN]
4H ; refresh
30M ; retry
Expand Down