diff --git a/main.go b/main.go index 6642d18..0313661 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ type CloudConfig struct { Groups []string `yaml:"groups"` Users []CloudConfigUser `yaml:"users"` WriteFiles []CloudConfigFile `yaml:"write_files"` + RunCmd []string `yaml:"runcmd"` } type CloudConfigUser struct { @@ -209,6 +210,17 @@ func processUserData(configDriveDir string) error { } } + // Run commands + for _, cmd := range cc.RunCmd { + cmdArgs := strings.Fields(cmd) + output, err := exec.Command(cmdArgs[0], cmdArgs[1:]...).CombinedOutput() + if err != nil { + log.Printf("Error running command '%s': %s\n%s", cmd, err, output) + } else { + log.Printf("Ran command '%s' successfully.\n%s ", cmd, output) + } + } + return nil }