summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2014-04-19 01:42:19 -0400
committerJoey Hess2014-04-19 01:42:19 -0400
commitf10c4d4aff6810a502cfc770013046e42efc33ef (patch)
treeb3ecd60d32166aca84dc0d72bbebff359778fa3e
parent9e578aca6b0914443c95f8691fd3ba39522f28fc (diff)
make primary dns server beat secondary if both are defined for a domain
Made my config file simpler..
-rw-r--r--Propellor/Attr.hs15
-rw-r--r--Propellor/Property/Dns.hs5
-rw-r--r--Propellor/Types/Attr.hs5
-rw-r--r--config-joey.hs2
4 files changed, 21 insertions, 6 deletions
diff --git a/Propellor/Attr.hs b/Propellor/Attr.hs
index fb94dc34..05ea3ff5 100644
--- a/Propellor/Attr.hs
+++ b/Propellor/Attr.hs
@@ -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
diff --git a/Propellor/Property/Dns.hs b/Propellor/Property/Dns.hs
index e47d6c32..4c93799f 100644
--- a/Propellor/Property/Dns.hs
+++ b/Propellor/Property/Dns.hs
@@ -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 =
diff --git a/Propellor/Types/Attr.hs b/Propellor/Types/Attr.hs
index f64b0487..8b7d3b09 100644
--- a/Propellor/Types/Attr.hs
+++ b/Propellor/Types/Attr.hs
@@ -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
diff --git a/config-joey.hs b/config-joey.hs
index b22f0e07..7fadd8bc 100644
--- a/config-joey.hs
+++ b/config-joey.hs
@@ -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")