summaryrefslogtreecommitdiff
path: root/doc/forum/passing_host_address_dynamically_to_propellor/comment_5_cd61e6fb0d5694575edb95728f0c8370._comment
blob: 79f721f14ca51307642e24cdb8764ed056df7871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[[!comment format=mdwn
 username="arnaud@30aba4d9f1742050874551d3ddc55ca8694809f8"
 nickname="arnaud"
 subject="Works like a charm..."
 date="2015-06-11T19:19:07Z"
 content="""
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 hosts

selectHost :: [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
```
"""]]