host templates

This commit is contained in:
Mikaël Cluseau
2024-04-15 15:32:43 +02:00
parent d4dbe709e0
commit 699b8e71a6
16 changed files with 315 additions and 46 deletions

View File

@ -2,8 +2,6 @@ package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"log"
@ -180,9 +178,20 @@ func (ctx *renderContext) renderConfigTo(buf io.Writer, configTemplate *clusters
return string(ba), err
}
extraFuncs["host_ip"] = func() string {
if ctx.Host.Template {
return "{{ host_ip }}"
}
return ctx.Host.IP
}
extraFuncs["host_name"] = func() string {
if ctx.Host.Template {
return "{{ host_name }}"
}
return ctx.Host.Name
}
extraFuncs["machine_id"] = func() string {
ba := sha1.Sum([]byte(ctx.Cluster.Name + "/" + ctx.Host.Name)) // TODO: check semantics of machine-id
return hex.EncodeToString(ba[:])
return "{{ machine_id }}"
}
extraFuncs["version"] = func() string { return Version }