Properties can now be satisfied differently on different operating systems.
This commit is contained in:
parent
576acfed33
commit
95ac5163da
|
@ -21,6 +21,13 @@ hostname name = pureAttrProperty ("hostname " ++ name) $
|
||||||
getHostName :: Propellor HostName
|
getHostName :: Propellor HostName
|
||||||
getHostName = asks _hostname
|
getHostName = asks _hostname
|
||||||
|
|
||||||
|
os :: System -> AttrProperty
|
||||||
|
os system = pureAttrProperty ("OS " ++ show system) $
|
||||||
|
\d -> d { _os = Just system }
|
||||||
|
|
||||||
|
getOS :: Propellor (Maybe System)
|
||||||
|
getOS = asks _os
|
||||||
|
|
||||||
cname :: Domain -> AttrProperty
|
cname :: Domain -> AttrProperty
|
||||||
cname domain = pureAttrProperty ("cname " ++ domain) (addCName domain)
|
cname domain = pureAttrProperty ("cname " ++ domain) (addCName domain)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ actionMessage desc a = do
|
||||||
return r
|
return r
|
||||||
|
|
||||||
warningMessage :: MonadIO m => String -> m ()
|
warningMessage :: MonadIO m => String -> m ()
|
||||||
warningMessage s = liftIO $ colorLine Vivid Red $ "** warning: " ++ s
|
warningMessage s = liftIO $ colorLine Vivid Magenta $ "** warning: " ++ s
|
||||||
|
|
||||||
colorLine :: ColorIntensity -> Color -> String -> IO ()
|
colorLine :: ColorIntensity -> Color -> String -> IO ()
|
||||||
colorLine intensity color msg = do
|
colorLine intensity color msg = do
|
||||||
|
@ -43,7 +43,7 @@ colorLine intensity color msg = do
|
||||||
|
|
||||||
errorMessage :: String -> IO a
|
errorMessage :: String -> IO a
|
||||||
errorMessage s = do
|
errorMessage s = do
|
||||||
warningMessage s
|
liftIO $ colorLine Vivid Red $ "** error: " ++ s
|
||||||
error "Cannot continue!"
|
error "Cannot continue!"
|
||||||
|
|
||||||
-- | Causes a debug message to be displayed when PROPELLOR_DEBUG=1
|
-- | Causes a debug message to be displayed when PROPELLOR_DEBUG=1
|
||||||
|
|
|
@ -10,6 +10,7 @@ import "mtl" Control.Monad.Reader
|
||||||
|
|
||||||
import Propellor.Types
|
import Propellor.Types
|
||||||
import Propellor.Types.Attr
|
import Propellor.Types.Attr
|
||||||
|
import Propellor.Attr
|
||||||
import Propellor.Engine
|
import Propellor.Engine
|
||||||
import Utility.Monad
|
import Utility.Monad
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
@ -91,6 +92,13 @@ check c property = Property (propertyDesc property) $ ifM (liftIO c)
|
||||||
, return NoChange
|
, return NoChange
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- | Makes a property that is satisfied differently depending on the host's
|
||||||
|
-- operating system.
|
||||||
|
--
|
||||||
|
-- Note that the operating system may not be declared for some hosts.
|
||||||
|
withOS :: Desc -> (Maybe System -> Propellor Result) -> Property
|
||||||
|
withOS desc a = Property desc $ a =<< getOS
|
||||||
|
|
||||||
boolProperty :: Desc -> IO Bool -> Property
|
boolProperty :: Desc -> IO Bool -> Property
|
||||||
boolProperty desc a = Property desc $ ifM (liftIO a)
|
boolProperty desc a = Property desc $ ifM (liftIO a)
|
||||||
( return MadeChange
|
( return MadeChange
|
||||||
|
|
|
@ -6,8 +6,6 @@ module Propellor.Types
|
||||||
( Host(..)
|
( Host(..)
|
||||||
, Attr
|
, Attr
|
||||||
, HostName
|
, HostName
|
||||||
, UserName
|
|
||||||
, GroupName
|
|
||||||
, Propellor(..)
|
, Propellor(..)
|
||||||
, Property(..)
|
, Property(..)
|
||||||
, RevertableProperty(..)
|
, RevertableProperty(..)
|
||||||
|
@ -19,16 +17,12 @@ module Propellor.Types
|
||||||
, requires
|
, requires
|
||||||
, Desc
|
, Desc
|
||||||
, Result(..)
|
, Result(..)
|
||||||
, System(..)
|
|
||||||
, Distribution(..)
|
|
||||||
, DebianSuite(..)
|
|
||||||
, Release
|
|
||||||
, Architecture
|
|
||||||
, ActionResult(..)
|
, ActionResult(..)
|
||||||
, CmdLine(..)
|
, CmdLine(..)
|
||||||
, PrivDataField(..)
|
, PrivDataField(..)
|
||||||
, GpgKeyId
|
, GpgKeyId
|
||||||
, SshKeyType(..)
|
, SshKeyType(..)
|
||||||
|
, module Propellor.Types.OS
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
|
@ -38,12 +32,10 @@ import "mtl" Control.Monad.Reader
|
||||||
import "MonadCatchIO-transformers" Control.Monad.CatchIO
|
import "MonadCatchIO-transformers" Control.Monad.CatchIO
|
||||||
|
|
||||||
import Propellor.Types.Attr
|
import Propellor.Types.Attr
|
||||||
|
import Propellor.Types.OS
|
||||||
|
|
||||||
data Host = Host [Property] (Attr -> Attr)
|
data Host = Host [Property] (Attr -> Attr)
|
||||||
|
|
||||||
type UserName = String
|
|
||||||
type GroupName = String
|
|
||||||
|
|
||||||
-- | Propellor's monad provides read-only access to attributes of the
|
-- | Propellor's monad provides read-only access to attributes of the
|
||||||
-- system.
|
-- system.
|
||||||
newtype Propellor p = Propellor { runWithAttr :: ReaderT Attr IO p }
|
newtype Propellor p = Propellor { runWithAttr :: ReaderT Attr IO p }
|
||||||
|
@ -119,22 +111,6 @@ instance Monoid Result where
|
||||||
mappend _ MadeChange = MadeChange
|
mappend _ MadeChange = MadeChange
|
||||||
mappend NoChange NoChange = NoChange
|
mappend NoChange NoChange = NoChange
|
||||||
|
|
||||||
-- | High level descritption of a operating system.
|
|
||||||
data System = System Distribution Architecture
|
|
||||||
deriving (Show)
|
|
||||||
|
|
||||||
data Distribution
|
|
||||||
= Debian DebianSuite
|
|
||||||
| Ubuntu Release
|
|
||||||
deriving (Show)
|
|
||||||
|
|
||||||
data DebianSuite = Experimental | Unstable | Testing | Stable | DebianRelease Release
|
|
||||||
deriving (Show, Eq)
|
|
||||||
|
|
||||||
type Release = String
|
|
||||||
|
|
||||||
type Architecture = String
|
|
||||||
|
|
||||||
-- | Results of actions, with color.
|
-- | Results of actions, with color.
|
||||||
class ActionResult a where
|
class ActionResult a where
|
||||||
getActionResult :: a -> (String, ColorIntensity, Color)
|
getActionResult :: a -> (String, ColorIntensity, Color)
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
module Propellor.Types.Attr where
|
module Propellor.Types.Attr where
|
||||||
|
|
||||||
|
import Propellor.Types.OS
|
||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
-- | The attributes of a host. For example, its hostname.
|
-- | The attributes of a host. For example, its hostname.
|
||||||
data Attr = Attr
|
data Attr = Attr
|
||||||
{ _hostname :: HostName
|
{ _hostname :: HostName
|
||||||
, _cnames :: S.Set Domain
|
, _cnames :: S.Set Domain
|
||||||
|
, _os :: Maybe System
|
||||||
, _sshPubKey :: Maybe String
|
, _sshPubKey :: Maybe String
|
||||||
|
|
||||||
, _dockerImage :: Maybe String
|
, _dockerImage :: Maybe String
|
||||||
|
@ -16,6 +19,7 @@ instance Eq Attr where
|
||||||
x == y = and
|
x == y = and
|
||||||
[ _hostname x == _hostname y
|
[ _hostname x == _hostname y
|
||||||
, _cnames x == _cnames y
|
, _cnames x == _cnames y
|
||||||
|
, _os x == _os y
|
||||||
, _sshPubKey x == _sshPubKey y
|
, _sshPubKey x == _sshPubKey y
|
||||||
|
|
||||||
, _dockerImage x == _dockerImage y
|
, _dockerImage x == _dockerImage y
|
||||||
|
@ -27,13 +31,14 @@ instance Show Attr where
|
||||||
show a = unlines
|
show a = unlines
|
||||||
[ "hostname " ++ _hostname a
|
[ "hostname " ++ _hostname a
|
||||||
, "cnames " ++ show (_cnames a)
|
, "cnames " ++ show (_cnames a)
|
||||||
|
, "OS " ++ show (_os a)
|
||||||
, "sshPubKey " ++ show (_sshPubKey a)
|
, "sshPubKey " ++ show (_sshPubKey a)
|
||||||
, "docker image " ++ show (_dockerImage a)
|
, "docker image " ++ show (_dockerImage a)
|
||||||
, "docker run params " ++ show (map (\mk -> mk "") (_dockerRunParams a))
|
, "docker run params " ++ show (map (\mk -> mk "") (_dockerRunParams a))
|
||||||
]
|
]
|
||||||
|
|
||||||
newAttr :: HostName -> Attr
|
newAttr :: HostName -> Attr
|
||||||
newAttr hn = Attr hn S.empty Nothing Nothing []
|
newAttr hn = Attr hn S.empty Nothing Nothing Nothing []
|
||||||
|
|
||||||
type HostName = String
|
type HostName = String
|
||||||
type Domain = String
|
type Domain = String
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
module Propellor.Types.OS where
|
||||||
|
|
||||||
|
type UserName = String
|
||||||
|
type GroupName = String
|
||||||
|
|
||||||
|
-- | High level descritption of a operating system.
|
||||||
|
data System = System Distribution Architecture
|
||||||
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
data Distribution
|
||||||
|
= Debian DebianSuite
|
||||||
|
| Ubuntu Release
|
||||||
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
data DebianSuite = Experimental | Unstable | Testing | Stable | DebianRelease Release
|
||||||
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
type Release = String
|
||||||
|
type Architecture = String
|
|
@ -29,7 +29,7 @@ hosts =
|
||||||
& Apt.buildDep ["git-annex"] `period` Daily
|
& Apt.buildDep ["git-annex"] `period` Daily
|
||||||
|
|
||||||
-- Nothing super-important lives here.
|
-- Nothing super-important lives here.
|
||||||
, standardSystem "clam.kitenet.net" Unstable
|
, standardSystem "clam.kitenet.net" Unstable "amd64"
|
||||||
& cleanCloudAtCost
|
& cleanCloudAtCost
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
& Network.ipv6to4
|
& Network.ipv6to4
|
||||||
|
@ -53,7 +53,7 @@ hosts =
|
||||||
& Apt.installed ["git-annex", "mtr", "screen"]
|
& Apt.installed ["git-annex", "mtr", "screen"]
|
||||||
|
|
||||||
-- Orca is the main git-annex build box.
|
-- Orca is the main git-annex build box.
|
||||||
, standardSystem "orca.kitenet.net" Unstable
|
, standardSystem "orca.kitenet.net" Unstable "amd64"
|
||||||
& Hostname.sane
|
& Hostname.sane
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
& Docker.configured
|
& Docker.configured
|
||||||
|
@ -65,7 +65,7 @@ hosts =
|
||||||
& Apt.buildDep ["git-annex"] `period` Daily
|
& Apt.buildDep ["git-annex"] `period` Daily
|
||||||
|
|
||||||
-- Important stuff that needs not too much memory or CPU.
|
-- Important stuff that needs not too much memory or CPU.
|
||||||
, standardSystem "diatom.kitenet.net" Stable
|
, standardSystem "diatom.kitenet.net" Stable "amd64"
|
||||||
& Hostname.sane
|
& Hostname.sane
|
||||||
& Ssh.hostKey SshDsa
|
& Ssh.hostKey SshDsa
|
||||||
& Ssh.hostKey SshRsa
|
& Ssh.hostKey SshRsa
|
||||||
|
@ -142,8 +142,9 @@ gitAnnexBuilder arch buildminute = Docker.container (arch ++ "-git-annex-builder
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
|
|
||||||
-- This is my standard system setup.
|
-- This is my standard system setup.
|
||||||
standardSystem :: HostName -> DebianSuite -> Host
|
standardSystem :: HostName -> DebianSuite -> Architecture -> Host
|
||||||
standardSystem hn suite = host hn
|
standardSystem hn suite arch = host hn
|
||||||
|
& os (System (Debian suite) arch)
|
||||||
& Apt.stdSourcesList suite `onChange` Apt.upgrade
|
& Apt.stdSourcesList suite `onChange` Apt.upgrade
|
||||||
& Apt.installed ["etckeeper"]
|
& Apt.installed ["etckeeper"]
|
||||||
& Apt.installed ["ssh"]
|
& Apt.installed ["ssh"]
|
||||||
|
@ -166,6 +167,7 @@ standardSystem hn suite = host hn
|
||||||
-- This is my standard container setup, featuring automatic upgrades.
|
-- This is my standard container setup, featuring automatic upgrades.
|
||||||
standardContainer :: Docker.ContainerName -> DebianSuite -> Architecture -> Host
|
standardContainer :: Docker.ContainerName -> DebianSuite -> Architecture -> Host
|
||||||
standardContainer name suite arch = Docker.container name (image system)
|
standardContainer name suite arch = Docker.container name (image system)
|
||||||
|
& os (System (Debian suite) arch)
|
||||||
& Apt.stdSourcesList suite
|
& Apt.stdSourcesList suite
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
where
|
where
|
||||||
|
|
|
@ -4,6 +4,8 @@ propellor (0.3.1) UNRELEASED; urgency=medium
|
||||||
* Support for provisioning hosts with ssh and gpg keys.
|
* Support for provisioning hosts with ssh and gpg keys.
|
||||||
* Obnam support.
|
* Obnam support.
|
||||||
* Apache support.
|
* Apache support.
|
||||||
|
* Properties can now be satisfied differently on different operating
|
||||||
|
systems.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 15:00:11 -0400
|
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 15:00:11 -0400
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ Library
|
||||||
Propellor.Engine
|
Propellor.Engine
|
||||||
Propellor.Exception
|
Propellor.Exception
|
||||||
Propellor.Types
|
Propellor.Types
|
||||||
|
Propellor.Types.OS
|
||||||
Other-Modules:
|
Other-Modules:
|
||||||
Propellor.Types.Attr
|
Propellor.Types.Attr
|
||||||
Propellor.CmdLine
|
Propellor.CmdLine
|
||||||
|
|
Loading…
Reference in New Issue