From 39ea639cc386179655ebf01194015ce7d0feeea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Thu, 24 Oct 2019 14:06:18 +1100 Subject: [PATCH] dir2config: hosts_by_cluster --- cmd/dkl-dir2config/render-cluster.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/dkl-dir2config/render-cluster.go b/cmd/dkl-dir2config/render-cluster.go index e2b3025..04ba477 100644 --- a/cmd/dkl-dir2config/render-cluster.go +++ b/cmd/dkl-dir2config/render-cluster.go @@ -39,6 +39,20 @@ func clusterFuncs(clusterSpec *clustersconfig.Cluster) map[string]interface{} { return fmt.Sprintf("{{ ca_dir %q %q }}", cluster, name), nil }, + "hosts_by_cluster": func(cluster string) (hosts []interface{}) { + for _, host := range src.Hosts { + if host.Cluster == cluster { + hosts = append(hosts, asMap(host)) + } + } + + if len(hosts) == 0 { + log.Printf("WARNING: no hosts in cluster %q", cluster) + } + + return + }, + "hosts_by_group": func(group string) (hosts []interface{}) { for _, host := range src.Hosts { if host.Group == group { @@ -47,7 +61,7 @@ func clusterFuncs(clusterSpec *clustersconfig.Cluster) map[string]interface{} { } if len(hosts) == 0 { - log.Fatalf("no hosts in group %q", group) + log.Printf("WARNING: no hosts in group %q", group) } return