From f4c0df84eeccbf27c0a3937cbd2aabff0a2420bd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 19 Apr 2014 01:55:32 -0400 Subject: [PATCH] secondaryFor --- Propellor/Property/Dns.hs | 20 +++++++++++++++++--- config-joey.hs | 14 +++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Propellor/Property/Dns.hs b/Propellor/Property/Dns.hs index 4c93799..68ce757 100644 --- a/Propellor/Property/Dns.hs +++ b/Propellor/Property/Dns.hs @@ -2,6 +2,7 @@ module Propellor.Property.Dns ( module Propellor.Types.Dns, primary, secondary, + secondaryFor, mkSOA, rootAddressesFrom, writeZoneFile, @@ -71,10 +72,23 @@ primary hosts domain soa rs = withwarnings (check needupdate baseprop) -- | Secondary dns server for a domain. -- +-- The primary server is determined by looking at the properties of other +-- hosts to find which one is configured as the primary. +-- -- Note that if a host is declared to be a primary and a secondary dns -- server for the same domain, the primary server config always wins. -secondary :: [Host] -> Domain -> HostName -> Property -secondary hosts domain master = pureAttrProperty desc (addNamedConf conf) +secondary :: [Host] -> Domain -> Property +secondary hosts domain = secondaryFor masters hosts domain + where + masters = M.keys $ M.filter ismaster $ hostAttrMap hosts + ismaster attr = case M.lookup domain (_namedconf attr) of + Nothing -> False + Just conf -> confType conf == Master && confDomain conf == domain + +-- | This variant is useful if the primary server does not have its DNS +-- configured via propellor. +secondaryFor :: [HostName] -> [Host] -> Domain -> -> Property +secondaryFor masters hosts domain = pureAttrProperty desc (addNamedConf conf) `requires` servingZones where desc = "dns secondary for " ++ domain @@ -82,7 +96,7 @@ secondary hosts domain master = pureAttrProperty desc (addNamedConf conf) { confDomain = domain , confType = Secondary , confFile = "db." ++ domain - , confMasters = hostAddresses master hosts + , confMasters = concatMap (\m -> hostAddresses m hosts) masters , confLines = ["allow-transfer { }"] } diff --git a/config-joey.hs b/config-joey.hs index 7fadd8b..a130612 100644 --- a/config-joey.hs +++ b/config-joey.hs @@ -246,15 +246,15 @@ cleanCloudAtCost = propertyList "cloudatcost cleanup" myDnsSecondary :: Property myDnsSecondary = propertyList "dns secondary for all my domains" - [ Dns.secondary hosts "kitenet.net" master - , Dns.secondary hosts "joeyh.name" master - , Dns.secondary hosts "ikiwiki.info" master - , Dns.secondary hosts "olduse.net" master - , Dns.secondary hosts "branchable.com" branchablemaster + [ Dns.secondaryFor wren hosts "kitenet.net" + , Dns.secondaryFor wren hosts "joeyh.name" + , Dns.secondaryFor wren hosts "ikiwiki.info" + , Dns.secondary hosts "olduse.net" + , Dns.secondaryFor branchable hosts "branchable.com" ] where - master = "wren.kitenet.net" - branchablemaster = "branchable.com" + wren = ["wren.kitenet.net"] + branchable = ["branchable.com"] main :: IO () main = defaultMain hosts