mirror of
https://github.com/rancher/os.git
synced 2025-07-03 10:06:13 +00:00
Set hostname prior to running DHCP
https://github.com/rancher/os/issues/627
This commit is contained in:
parent
60ef1d4a60
commit
ea50b5968a
@ -168,17 +168,26 @@ func fetchUserData() ([]byte, datasource.Metadata, error) {
|
|||||||
return userDataBytes, metadata, nil
|
return userDataBytes, metadata, 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
|
||||||
|
}
|
||||||
|
|
||||||
func executeCloudConfig() error {
|
func executeCloudConfig() error {
|
||||||
cc, err := rancherConfig.LoadConfig()
|
cc, err := rancherConfig.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.Hostname != "" {
|
if err := SetHostname(cc); err != nil {
|
||||||
//set hostname
|
return err
|
||||||
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 {
|
if len(cc.SSHAuthorizedKeys) > 0 {
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/rancher/netconf"
|
"github.com/rancher/netconf"
|
||||||
|
"github.com/rancher/os/cmd/cloudinit"
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,6 +21,8 @@ func Main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// Purposely ignore error
|
||||||
|
cloudinit.SetHostname(cfg)
|
||||||
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
|
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user