From d7065a88d706a232e9db02dab7fc3711b5d36bbd Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 20 Jan 2026 20:09:27 +0100 Subject: [PATCH] config: add .Host and .Hostname to templates .Host is the hostname as configured in hosts.yaml (most likely a FQDN). .Hostname is just the name (before the first dot). --- cmd/safcm/config/templates.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/safcm/config/templates.go b/cmd/safcm/config/templates.go index fd46182..059d89b 100644 --- a/cmd/safcm/config/templates.go +++ b/cmd/safcm/config/templates.go @@ -68,7 +68,8 @@ func LoadTemplates(group string, files map[string]*safcm.File, return fmt.Errorf("%s: invalid %v", path, err) } err = tmpl.Execute(&buf, &templateArgs{ - host: host, + Host: host, + Hostname: strings.Split(host, ".")[0], groups: groupsMap, allHosts: allHostsMap, allGroups: allGroupsMap, @@ -84,7 +85,8 @@ func LoadTemplates(group string, files map[string]*safcm.File, // templateArgs is passed to .Execute() of the template. type templateArgs struct { - host string + Host string + Hostname string groups map[string]bool allHosts map[string]bool allGroups map[string]bool @@ -97,7 +99,7 @@ func (t *templateArgs) IsHost(host string) bool { if !t.allHosts[host] { panic(fmt.Sprintf("host %q does not exist", host)) } - return t.host == host + return t.Host == host } func (t *templateArgs) InGroup(group string) bool { // Don't permit invalid groups to detect typos; detected groups cannot be -- 2.55.0