From 019d49f498bde5e4040e8b6171d5862c094a5e0b Mon Sep 17 00:00:00 2001 From: Adam Henry Lewenberg <adamhl@stanford.edu> Date: Fri, 9 Oct 2015 12:19:02 -0700 Subject: [PATCH] templatize dnsmasq conf file and remove need for cache_packages.pp --- manifests/dns.pp | 2 +- manifests/dns/cache.pp | 57 +++++++++++++++++-- manifests/dns/cache_packages.pp | 17 ++++-- .../etc/dnsmasq.d/stanford-dnscache.conf.erb | 4 +- 4 files changed, 69 insertions(+), 11 deletions(-) rename files/dns/etc/dnsmasq.d/stanford-dnscache.conf => templates/dns/etc/dnsmasq.d/stanford-dnscache.conf.erb (59%) diff --git a/manifests/dns.pp b/manifests/dns.pp index 9887d90..c36d7fd 100644 --- a/manifests/dns.pp +++ b/manifests/dns.pp @@ -25,7 +25,7 @@ class base::dns( $livermore = false } - if !$no_resolv_conf { + if (!$no_resolv_conf) { base::dns::resolv_conf { $::fqdn_lc: ensure => present, dns_cache => $dns_cache, diff --git a/manifests/dns/cache.pp b/manifests/dns/cache.pp index 6ff6934..c891f8f 100644 --- a/manifests/dns/cache.pp +++ b/manifests/dns/cache.pp @@ -1,11 +1,60 @@ # This class adds a reference to a local DNS caching server. -class base::dns::cache inherits base::dns { - include base::dns::cache_packages +# +# NOTE: This class only works with Debian. +# +# $cache_size_entries: the number of entries to cache. +# Default: 10000 - # We need daemontools for wheezy servers. +class base::dns::cache( + $cache_size_entries = 10000 +) inherits base::dns { + + if ($::osfamily != 'Debian') { + fail 'base::dns::cache_packages only works with Debian' + } + + Base::Dns::Resolv_conf[$::fqdn_lc] { dns_cache => true } + + # We use stanford-dnscache for wheezy and dnsmasq for jessie and later. if ($::lsbdistcodename == 'wheezy') { + # WHEEZY + include base::daemontools + + # Stanford package for DNS caching. + package { 'stanford-dnscache': + ensure => present, + notify => Exec['chown dnslog:dnslog /var/log/dnscache'], + } + + # This is required because ownership is wrong on reinstall of packages + # but not on initial install. + exec {'chown dnslog:dnslog /var/log/dnscache': + command => 'chown -R dnslog:dnslog /var/log/dnscache', + refreshonly => true, + } + } else { + # JESSIE and beyond + + package { 'dnsmasq': + ensure => present, + } + + # Call the template for /etc/dnsmasq.d/stanford-dnscache.conf. This + # template uses the $cache_size_entries class parameter. + file {'/etc/dnsmasq.d/stanford-dnscache.conf': + content => template('base/dns/etc/dnsmasq.d/stanford-dnscache.conf.erb'), + require => Package['dnsmasq'], + notify => Service['dnsmasq'], + } + + # Define the service and make sure it runs. Restart the service if + # /etc/resolv.conf changes. + service { 'dnsmasq': + ensure => 'running', + require => Package['dnsmasq'], + subscribe => File['/etc/resolv.conf'], + } } - Base::Dns::Resolv_conf[$::fqdn_lc] { dns_cache => true } } diff --git a/manifests/dns/cache_packages.pp b/manifests/dns/cache_packages.pp index f6e648b..b2c9ef4 100644 --- a/manifests/dns/cache_packages.pp +++ b/manifests/dns/cache_packages.pp @@ -1,6 +1,13 @@ -# This class only works with Debian. +# REMOVE THIS FILE -class base::dns::cache_packages { +# NOTE: This class only works with Debian. + +# $cache_size_entries: the number of entries to cache. +# Default: 10000 + +class base::dns::cache_packages( + $cache_size_entries = 10000 +){ if ($::osfamily != 'Debian') { fail 'base::dns::cache_packages only works with Debian' @@ -27,8 +34,10 @@ class base::dns::cache_packages { ensure => present, } + # Call the template for /etc/dnsmasq.d/stanford-dnscache.conf. This + # template uses the $cache_size_entries class parameter. file {'/etc/dnsmasq.d/stanford-dnscache.conf': - source => 'puppet:///modules/base/dns/etc/dnsmasq.d/stanford-dnscache.conf', + content => template('base/dns/etc/dnsmasq.d/stanford-dnscache.conf') require => Package['dnsmasq'], notify => Service['dnsmasq'], } @@ -41,4 +50,4 @@ class base::dns::cache_packages { subscribe => File['/etc/resolv.conf'], } } -} +} diff --git a/files/dns/etc/dnsmasq.d/stanford-dnscache.conf b/templates/dns/etc/dnsmasq.d/stanford-dnscache.conf.erb similarity index 59% rename from files/dns/etc/dnsmasq.d/stanford-dnscache.conf rename to templates/dns/etc/dnsmasq.d/stanford-dnscache.conf.erb index fd1ef71..5b4e7bf 100644 --- a/files/dns/etc/dnsmasq.d/stanford-dnscache.conf +++ b/templates/dns/etc/dnsmasq.d/stanford-dnscache.conf.erb @@ -4,5 +4,5 @@ listen-address=127.0.0.1 # really bind only the interfaces it is listening on bind-interfaces -# Cache up to 10000 addresses -cache-size=10000 +# Cache up to <%= @cache_size_entries %> addresses +cache-size=<%= @cache_size_entries %> -- GitLab