I would like to be able to pass the address of a host dynamically to propellor, e.g. to do something like ./propellor 1.2.3.4
so that I can apply some predefined set of properties.
I tried to implement, it compiles just fine, but does fail to run properly on the remote (or even local) host because defaultMain
does some transformation of command-line and of course the host name/address does not exist statically in the git repo that's built and run on the remote host. Would there be another way to do what I want?
What's the use case here?
I think maybe you're trying to deploy basically the same set of properties to multiple hosts. And perhaps don't want to have the list of hosts in the config.hs file. If that's the goal, it seems you could accomplish it by writing a function like:
Or more generally,
And then you can map over the set of IP addresses to generate the the [Host] list for propellor. Or could even read a data file (that would need to be checked into the git repo) and use it to constuct the [Host] list at runtime.
But maybe I misunderstood the use case..
We create/destroy dynamically hosts which have different purpose: CI, Dev boxes, Testing... IP of these hosts is unknown and assign by our provider (Digital Ocean) so what I would like to do is something like:
$ create-host ... IP: 1.2.3.4 $ ./propellor 1.2.3.4
But indeed the idea of having a local
hosts
file makes sense, or even ahosts/
directory to which I output files containing IPs.Or teach propellor --spin how to create Digital Ocean, AWS, etc VMs, as described in HostingProvider for AWS.
I guess that even if it created the hosts, it would make sense to have a static host list with their IPs.
That makes sense. Indeed, that's the direction I was heading to, because currently our VM deployment scripts are in shell and I wanted to port them to Haskell and integrate in the provisioning process. Thanks for the idea, I will see where it goes.
I implemented this feature using a file, aptly named
hosts
that is versioned in the repo and populated (at the moment manually but will be automatic...) when boxes are created in DO. Then the following main will extract the information and create hosts config to be passed to main from propellor, reading the needed file:`` main :: IO () main = do h <- map words <$> lines <$> readFile "hosts"
catch` (\ (_ :: IOException) -> return "") let hosts = map selectHost h defaultMain hostsselectHost :: [String] -> Host selectHost ["prod",ip,sha1] = host ip & Lending.lendingHost sha1 selectHost ["prod",ip] = host ip & Lending.lendingHost currentSha1 selectHost ["monitor",name,ip] = host name & Monitoring.monitoringHost ip selectHost h = error $ "doesn't know how to handle host definition " ++ show h ```