import (
"fmt"
"os"
+ "strings"
"gopkg.in/yaml.v2"
)
type Host struct {
Name string `yaml:"name"`
+
+ SshUser string `yaml:"ssh_user"`
}
func LoadHosts() (*Hosts, error) {
hostMap := make(map[string]*Host)
for _, x := range hostList {
+ errPrefix := fmt.Sprintf("%s: host %q:", path, x.Name)
+ if x.Name == GroupAll {
+ return nil, fmt.Errorf(
+ "%s conflict with pre-defined group %q",
+ errPrefix, x.Name)
+ }
+ if strings.HasPrefix(x.Name, GroupDetectedPrefix) {
+ return nil, fmt.Errorf(
+ "%s name must not start with %q "+
+ "(reserved for detected groups)",
+ errPrefix, GroupDetectedPrefix)
+ }
+ if strings.Contains(x.Name, GroupSpecialSeparator) {
+ return nil, fmt.Errorf(
+ "%s name must not contain %q",
+ errPrefix, GroupSpecialSeparator)
+ }
+
+ if hostMap[x.Name] != nil {
+ return nil, fmt.Errorf("%s host name already exists",
+ errPrefix)
+ }
hostMap[x.Name] = x
}