diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-31 21:03:08 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-31 21:03:08 -0400 |
| commit | 2588cab6a2b8e3097fa23b3527d9fa8d9c53d903 (patch) | |
| tree | c6768a2c122b2d466506edbe856a100d0c7ec033 /src/Propellor/Engine.hs | |
| parent | 67549db9e95e03c449f1ad6969605801cd731656 (diff) | |
| parent | 179301f58dea22feb945004389a56662fe255138 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Engine.hs')
| -rw-r--r-- | src/Propellor/Engine.hs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs index 55ce7f77..ca0f7265 100644 --- a/src/Propellor/Engine.hs +++ b/src/Propellor/Engine.hs @@ -5,20 +5,22 @@ module Propellor.Engine where import System.Exit import System.IO import Data.Monoid +import Control.Applicative import System.Console.ANSI import "mtl" Control.Monad.Reader import Propellor.Types import Propellor.Message import Propellor.Exception +import Propellor.Attr -runPropellor :: Attr -> Propellor a -> IO a -runPropellor attr a = runReaderT (runWithAttr a) attr +runPropellor :: Host -> Propellor a -> IO a +runPropellor host a = runReaderT (runWithHost a) host -mainProperties :: Attr -> [Property] -> IO () -mainProperties attr ps = do - r <- runPropellor attr $ - ensureProperties [Property "overall" (ensureProperties ps) id] +mainProperties :: Host -> IO () +mainProperties host = do + r <- runPropellor host $ + ensureProperties [Property "overall" (ensureProperties $ hostProperties host) mempty] setTitle "propellor: done" hFlush stdout case r of @@ -30,8 +32,18 @@ ensureProperties ps = ensure ps NoChange where ensure [] rs = return rs ensure (l:ls) rs = do - r <- actionMessage (propertyDesc l) (ensureProperty l) + hn <- asks hostName + r <- actionMessageOn hn (propertyDesc l) (ensureProperty l) ensure ls (r <> rs) ensureProperty :: Property -> Propellor Result ensureProperty = catchPropellor . propertySatisfy + +-- | Lifts an action into a different host. +-- +-- For example, `fromHost hosts "otherhost" getSshPubKey` +fromHost :: [Host] -> HostName -> Propellor a -> Propellor (Maybe a) +fromHost l hn getter = case findHost l hn of + Nothing -> return Nothing + Just h -> liftIO $ Just <$> + runReaderT (runWithHost getter) h |
