From: Peter Palfrader Date: Tue, 10 Sep 2019 14:54:41 +0000 (+0200) Subject: resolv.conf cleanup X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=471d375994f5b5ceadaafa80778406d71fecb86a;p=mirror%2Fdsa-puppet.git resolv.conf cleanup --- diff --git a/hieradata/common.yaml b/hieradata/common.yaml index d79bbf8b9..df8ab6817 100644 --- a/hieradata/common.yaml +++ b/hieradata/common.yaml @@ -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 diff --git a/modules/resolv/manifests/init.pp b/modules/resolv/manifests/init.pp index 3447733a3..669fe4c33 100644 --- a/modules/resolv/manifests/init.pp +++ b/modules/resolv/manifests/init.pp @@ -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'); diff --git a/modules/resolv/templates/resolv.conf.erb b/modules/resolv/templates/resolv.conf.erb index 773337420..2a9f4631d 100644 --- a/modules/resolv/templates/resolv.conf.erb +++ b/modules/resolv/templates/resolv.conf.erb @@ -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 -%>