resolv.conf cleanup
authorPeter Palfrader <peter@palfrader.org>
Tue, 10 Sep 2019 14:54:41 +0000 (16:54 +0200)
committerPeter Palfrader <peter@palfrader.org>
Tue, 10 Sep 2019 14:54:46 +0000 (16:54 +0200)
hieradata/common.yaml
modules/resolv/manifests/init.pp
modules/resolv/templates/resolv.conf.erb

index d79bbf8..df8ab68 100644 (file)
@@ -1,6 +1,14 @@
 ---
+
+lookup_options:
+  # with merge: unique entries in other hiera sources add to the array
+  searchpaths:
+    merge: unique
+  apt::sources::debian::location:
+    merge: unique
+
 nameservers: []
-searchpaths: []
+searchpaths: ['debian.org']
 resolvoptions: []
 allow_dns_query: []
 role_config__mirrors:
@@ -18,11 +26,6 @@ paths:
   letsencrypt_dir: '/srv/puppet.debian.org/from-letsencrypt'
   auto_certs_dir: '/srv/puppet.debian.org/ca/RESULT/certs'
   auto_clientcerts_dir: '/srv/puppet.debian.org/ca/RESULT/clientcerts'
-
-lookup_options:
-  # entries in other hiera sources add to the array
-  apt::sources::debian::location:
-    merge: unique
 apt::sources::debian::location: 'http://deb.debian.org/debian/'
 
 # all of these should be retired in favour of including the class role
index 3447733..669fe4c 100644 (file)
@@ -1,8 +1,12 @@
 class resolv {
 
-       $ns   = hiera('nameservers')
-       $sp   = hiera('searchpaths')
-       $opts = hiera('resolvoptions')
+       $nameservers = $facts['unbound'] ? {
+               true    => ['127.0.0.1'],
+               default => hiera('nameservers'),
+       }
+
+       $searchpaths = hiera('searchpaths')
+       $resolvoptions = hiera('resolvoptions')
 
        file { '/etc/resolv.conf':
                        content => template('resolv/resolv.conf.erb');
index 7733374..2a9f463 100644 (file)
@@ -3,35 +3,24 @@
 ### USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
 ###
 
-<%
-searchpaths = []
-searchpaths += @sp
-searchpaths << "debian.org" -%>
-search <%= searchpaths.to_a.flatten.join(" ") %>
-<%
-nameservers = []
-if %w{draghi}.include?(@hostname)
-  nameservers << "127.0.0.1"
-end
-nameservers += @ns
 
-if @unbound
-  nameservers = ['127.0.0.1']
-end
+<%
+nameservers = @nameservers
 
 if nameservers.empty?
-  #raise Puppet::ParseError, "Something has gone wrong writing resolv.conf.  No nameservers to use!"
   scope.function_warning(["Something has gone wrong writing resolv.conf.  No nameservers to use - using google's!"])
   nameservers << '8.8.8.8'
   nameservers << '8.8.4.4'
 end
 
-nameservers.to_a.flatten.each do |nms| -%>
-nameserver <%= nms %>
+%>
+
+<% if @searchpaths.size() > 0 %>
+options <%= @searchpaths.join(" ") %>
 <% end -%>
-<%
-options  = []
-options += @opts -%>
-<% options.to_a.flatten.each do |opt| -%>
-options <%= opt %>
+
+<%= nameservers.map{ |ns| "nameserver #{ns}"}.join("\n") %>
+
+<% if @resolvoptions.size() > 0 %>
+options <%= @searchpaths.join(" ") %>
 <% end -%>