]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: add .Host and .Hostname to templates
authorSimon Ruderich <simon.ruderich@fau.de>
Tue, 20 Jan 2026 19:09:27 +0000 (20:09 +0100)
committerSimon Ruderich <simon.ruderich@fau.de>
Tue, 20 Jan 2026 19:13:06 +0000 (20:13 +0100)
.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

index fd46182a0b75136506e4ec555244318b960c0c0c..059d89bb3dd69df4916f31cb9ba142eec8e64f02 100644 (file)
@@ -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