dir2config: hosts_by_cluster

This commit is contained in:
Mikaël Cluseau 2019-10-24 14:06:18 +11:00
parent b5b8514c59
commit 39ea639cc3

View File

@ -39,6 +39,20 @@ func clusterFuncs(clusterSpec *clustersconfig.Cluster) map[string]interface{} {
return fmt.Sprintf("{{ ca_dir %q %q }}", cluster, name), nil 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{}) { "hosts_by_group": func(group string) (hosts []interface{}) {
for _, host := range src.Hosts { for _, host := range src.Hosts {
if host.Group == group { if host.Group == group {
@ -47,7 +61,7 @@ func clusterFuncs(clusterSpec *clustersconfig.Cluster) map[string]interface{} {
} }
if len(hosts) == 0 { if len(hosts) == 0 {
log.Fatalf("no hosts in group %q", group) log.Printf("WARNING: no hosts in group %q", group)
} }
return return