INNER CODE UNIT · Go
runTaskForTarget
umputun/spot · cmd/spot/main.go:447
func runTaskForTarget(ctx context.Context, r *runner.Process, taskName, targetName string) error {
st := time.Now()
res, err := r.Run(ctx, taskName, targetName)
if err != nil {
return fmt.Errorf("can't run task %q for target %q: %w", taskName, targetName, err)
}
log.Printf("[INFO] completed: hosts:%d, commands:%d in %v\n",
res.Hosts, res.Commands, time.Since(st).Truncate(100*time.Millisecond))
r.Playbook.UpdateTasksTargets(res.Vars) // for dynamic targets
r.Playbook.UpdateRegisteredVars(res.Registered) // for registered vars, cross-task
return nil
}
// get the list of targets for the task. Usually this is just a list of all targets from the command line,
// however, if the task has targets defined AND cli has the default target, then only those targets will be used.
func targetsForTask(targets []string, taskName string, pbook runner.Playbook) []string {
if len(targets) > 1 || (len(targets) == 1 && targets[0] != "default") {
// non-default target specified on command line