예제 #1
0
func (play *Play) Run(env *Environment) error {
	env.report.StartTasks(play)

	pe := &PlayEnv{Vars: make(Vars), lispScope: lisp.NewScope()}
	pe.Init(env)

	pe.ImportVars(play.Vars)

	for _, file := range play.VarsFiles {
		switch file := file.(type) {
		case string:
			pe.ImportVarsFile(play.path(file))
			break
		case []interface{}:
			for _, ent := range file {
				exp, err := pe.ExpandVars(ent.(string))

				if err != nil {
					continue
				}

				epath := play.path(exp)

				if _, err := os.Stat(epath); err == nil {
					err = pe.ImportVarsFile(epath)

					if err != nil {
						return err
					}

					break
				}
			}
		}
	}

	for _, task := range play.Tasks {
		err := task.Run(env, pe)

		if err != nil {
			return err
		}
	}

	env.report.FinishTasks(play)

	pe.wait.Wait()

	env.report.StartHandlers(play)

	for _, task := range play.Handlers {
		if pe.ShouldRunHandler(task.Name()) {
			err := task.Run(env, pe)

			if err != nil {
				return err
			}
		}
	}

	env.report.FinishHandlers(play)

	return nil
}
예제 #2
0
파일: playbook.go 프로젝트: jc00ke/tachyon
func (play *Play) Run(env *Environment) error {
	fmt.Printf("== tasks\n")

	pe := &PlayEnv{Vars: make(Vars), lispScope: lisp.NewScope()}
	pe.Init()

	for k, v := range play.Vars {
		pe.Set(k, v)
	}

	for _, file := range play.VarsFiles {
		switch file := file.(type) {
		case string:
			play.loadVarsFile(file, pe)
			break
		case []interface{}:
			for _, ent := range file {
				exp, err := env.ExpandVars(ent.(string), pe)

				if err != nil {
					continue
				}

				epath := path.Join("test", exp)

				if _, err := os.Stat(epath); err == nil {
					err = play.loadVarsFile(exp, pe)

					if err != nil {
						return err
					}

					break
				}
			}
		}
	}

	for _, task := range play.Tasks {
		err := task.Run(env, pe)

		if err != nil {
			return err
		}
	}

	fmt.Printf("== Waiting on all tasks to finish...\n")
	pe.wait.Wait()

	fmt.Printf("== Running any handlers\n")

	for _, task := range play.Handlers {
		if pe.ShouldRunHandler(task.Name()) {
			err := task.Run(env, pe)

			if err != nil {
				return err
			}
		}
	}

	return nil
}