// Load shedule information from all task.yml func (scheduler *Scheduler) load() error { for _, path := range config.Files { if path == "" { continue } if !util.Exists(path) { log.Warnf("Schedule file does not found(%s)", path) continue } log.Info(fmt.Sprintf("Load %s", path)) d, err := ioutil.ReadFile(path) if err != nil { return errors.New(fmt.Sprintf("Failed to load config file(%s)\n\t%s", path, err)) } var schedule Schedule schedule.Default = taskDefault() if err := yaml.Unmarshal([]byte(d), &schedule); err != nil { return errors.New(fmt.Sprintf("Failed to unmarshal json(%s)\n\t%s", path, err)) } patternName := patternName(path) schedule.PostUnmarshal(path, patternName) scheduler.schedules[patternName] = schedule log.Debug(&schedule) } return nil }
func (o *ChefOperation) executeBerkshelf() error { // Check Berksfile in target pattern if !util.Exists(filepath.Join(o.patternDir(), "Berksfile")) { log.Debug("chef: Skip berkshelf because Berksfile doesn't found in pattern directory") return nil } // Execute berkshelf and ignore specified error log.Info("chef: Execute berkshelf") cmd := exec.Command("berks", "vendor", "cookbooks") cmd.Dir = o.patternDir() env := os.Environ() env = append(env, "HOME=/root") cmd.Env = env out, err := cmd.CombinedOutput() log.Debug(string(out)) if err != nil { if e2, ok := err.(*exec.ExitError); ok { if s, ok := e2.Sys().(syscall.WaitStatus); ok { if s.ExitStatus() == BERKS_VENDOR_ERROR { return nil } } } } return err }
// Filter runlist by JSON file existance in roles directory func (o *ChefOperation) ensureRunList(runlist []string) []string { var results []string r, _ := regexp.Compile("^role\\[(.*)\\]$") for _, v := range runlist { matches := r.FindStringSubmatch(v) if len(matches) > 0 { if !util.Exists(filepath.Join(o.patternDir(), "roles", matches[1]+".json")) { continue } } results = append(results, v) } return results }