Skip to content

Commit

Permalink
chore: template playbook runsOn
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Oct 10, 2024
1 parent 8212b24 commit 3356c72
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions playbook/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/flanksource/duty/context"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
"github.com/flanksource/gomplate/v3"
"github.com/google/uuid"
"github.com/samber/lo"
"github.com/samber/oops"
Expand Down Expand Up @@ -158,6 +159,26 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
return nil, err
}

// Template run's spec (runsOn)
var runSpec v1.PlaybookSpec
if err := json.Unmarshal(playbook.Spec, &runSpec); err != nil {
return nil, ctx.Oops().Wrap(err)
}
var runsOn []string
for _, specRunOn := range runSpec.RunsOn {
output, err := ctx.RunTemplate(gomplate.Template{Template: specRunOn}, templateEnv.AsMap())
if err != nil {
return nil, ctx.Oops().Wrap(err)
}
runsOn = append(runsOn, output)
}
runSpec.RunsOn = runsOn

run.Spec, err = json.Marshal(runSpec)
if err != nil {
return nil, ctx.Oops().Wrap(err)
}

if err := savePlaybookRun(ctx, &run); err != nil {
return nil, ctx.Oops().Wrapf(err, "failed to create playbook run")
}
Expand Down

0 comments on commit 3356c72

Please sign in to comment.