feat(etc-hosts) add support for manage_etc_hosts: localhost

This feature is based on https://github.com/number5/cloud-init/blob/master/doc/examples/cloud-config.txt#L447:L482
This commit is contained in:
Gabriel Monroy
2014-04-01 16:02:12 -06:00
parent 23d02363ee
commit 4d02e1da8e
4 changed files with 148 additions and 4 deletions

View File

@@ -17,9 +17,10 @@ type CloudConfig struct {
Units []system.Unit
OEM OEMRelease
}
WriteFiles []system.File `yaml:"write_files"`
Hostname string
Users []system.User
WriteFiles []system.File `yaml:"write_files"`
Hostname string
Users []system.User
ManageEtcHosts string `yaml:"manage_etc_hosts"`
}
func NewCloudConfig(contents string) (*CloudConfig, error) {
@@ -154,7 +155,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
commands["systemd-networkd.service"] = "restart"
} else {
if unit.Command != "" {
commands[unit.Name] = unit.Command
commands[unit.Name] = unit.Command
}
}
}
@@ -169,5 +170,15 @@ func Apply(cfg CloudConfig, env *Environment) error {
}
}
if cfg.ManageEtcHosts != "" {
if err := WriteEtcHosts(cfg.ManageEtcHosts, env.Root()); err != nil {
log.Fatalf("Failed to write /etc/hosts to filesystem: %v", err)
}
log.Printf("Wrote /etc/hosts file to filesystem")
}
return nil
}