make primary dns server beat secondary if both are defined for a domain

Made my config file simpler..
This commit is contained in:
Joey Hess 2014-04-19 01:42:19 -04:00
parent 9e578aca6b
commit f10c4d4aff
4 changed files with 21 additions and 6 deletions

View File

@ -49,10 +49,21 @@ alias domain = pureAttrProperty ("aka " ++ domain)
addDNS :: Record -> SetAttr
addDNS record d = d { _dns = S.insert record (_dns d) }
-- | Adds a DNS NamedConf stanza.
--
-- Note that adding a Master stanza for a domain always overrides an
-- existing Secondary stanza, while a Secondary stanza is only added
-- when there is no existing Master stanza.
addNamedConf :: NamedConf -> SetAttr
addNamedConf conf d = d { _namedconf = S.insert conf (_namedconf d) }
addNamedConf conf d = d { _namedconf = new }
where
m = _namedconf d
domain = confDomain conf
new = case (confType conf, confType <$> M.lookup domain m) of
(Secondary, Just Master) -> m
_ -> M.insert domain conf m
getNamedConf :: Propellor (S.Set NamedConf)
getNamedConf :: Propellor (M.Map Domain NamedConf)
getNamedConf = asks _namedconf
sshPubKey :: String -> Property

View File

@ -70,6 +70,9 @@ primary hosts domain soa rs = withwarnings (check needupdate baseprop)
in z /= oldzone || oldserial < sSerial (zSOA zone)
-- | Secondary dns server for a domain.
--
-- 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)
`requires` servingZones
@ -95,7 +98,7 @@ servingZones = property "serving configured dns zones" go
zs <- getNamedConf
ensureProperty $
hasContent namedConfFile $
concatMap confStanza $ S.toList zs
concatMap confStanza $ M.elems zs
confStanza :: NamedConf -> [Line]
confStanza c =

View File

@ -4,6 +4,7 @@ import Propellor.Types.OS
import qualified Propellor.Types.Dns as Dns
import qualified Data.Set as S
import qualified Data.Map as M
-- | The attributes of a host. For example, its hostname.
data Attr = Attr
@ -11,7 +12,7 @@ data Attr = Attr
, _os :: Maybe System
, _sshPubKey :: Maybe String
, _dns :: S.Set Dns.Record
, _namedconf :: S.Set Dns.NamedConf
, _namedconf :: M.Map Dns.Domain Dns.NamedConf
, _dockerImage :: Maybe String
, _dockerRunParams :: [HostName -> String]
@ -42,6 +43,6 @@ instance Show Attr where
]
newAttr :: HostName -> Attr
newAttr hn = Attr hn Nothing Nothing S.empty S.empty Nothing []
newAttr hn = Attr hn Nothing Nothing S.empty M.empty Nothing []
type SetAttr = Attr -> Attr

View File

@ -90,7 +90,6 @@ hosts = -- (o) `
& Ssh.hostKey SshEcdsa
& Apt.unattendedUpgrades
& Apt.serviceInstalledRunning "ntp"
& myDnsSecondary
& Postfix.satellite
& Apt.serviceInstalledRunning "apache2"
@ -122,6 +121,7 @@ hosts = -- (o) `
& alias "nntp.olduse.net"
& JoeySites.oldUseNetServer hosts
& myDnsSecondary
& Dns.primary hosts "olduse.net"
( Dns.mkSOA "ns1.kitenet.net" 100
[ NS (AbsDomain "ns1.kitenet.net")