func executeCloudConfig() error { cc, err := rancherConfig.LoadConfig() if err != nil { return err } if cc.Hostname != "" { //set hostname if err := hostname.SetHostname(cc.Hostname); err != nil { log.WithFields(log.Fields{"err": err, "hostname": cc.Hostname}).Error("Error setting hostname") } } if len(cc.SSHAuthorizedKeys) > 0 { authorizeSSHKeys("rancher", cc.SSHAuthorizedKeys, sshKeyName) authorizeSSHKeys("docker", cc.SSHAuthorizedKeys, sshKeyName) } for _, file := range cc.WriteFiles { f := system.File{File: file} fullPath, err := system.WriteFile(&f, "/") if err != nil { log.WithFields(log.Fields{"err": err, "path": fullPath}).Error("Error writing file") continue } log.Printf("Wrote file %s to filesystem", fullPath) } return nil }
func SetHostname(cc *rancherConfig.CloudConfig) error { if cc.Hostname != "" { //set hostname if err := hostname.SetHostname(cc.Hostname); err != nil { log.WithFields(log.Fields{"err": err, "hostname": cc.Hostname}).Error("Error setting hostname") return err } } return nil }