1 // Config: parse hosts.yaml
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024 Simon Ruderich
22 Name string `yaml:"name"`
24 SshUser string `yaml:"ssh_user"`
27 func LoadHosts() (*Hosts, error) {
28 const path = "hosts.yaml"
31 x, err := os.ReadFile(path)
35 err = yaml.UnmarshalStrict(x, &hostList)
37 return nil, fmt.Errorf("%s: failed to load: %v", path, err)
40 hostMap := make(map[string]*Host)
41 for _, x := range hostList {
42 errPrefix := fmt.Sprintf("%s: host %q:", path, x.Name)
43 if x.Name == GroupAll {
44 return nil, fmt.Errorf(
45 "%s conflict with pre-defined group %q",
48 if strings.HasPrefix(x.Name, GroupDetectedPrefix) {
49 return nil, fmt.Errorf(
50 "%s name must not start with %q "+
51 "(reserved for detected groups)",
52 errPrefix, GroupDetectedPrefix)
54 if strings.Contains(x.Name, GroupSpecialSeparator) {
55 return nil, fmt.Errorf(
56 "%s name must not contain %q",
57 errPrefix, GroupSpecialSeparator)
60 if hostMap[x.Name] != nil {
61 return nil, fmt.Errorf("%s host name already exists",