Skip to content

Commit

Permalink
fix(ansible): init vaults before getting ansible params
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Dec 18, 2024
1 parent cef857c commit d8aba18
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions db/Task.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Task struct {
Params MapStringAnyField `db:"params" json:"params"`
}

func (task *Task) GetParams(target interface{}) (err error) {
func (task *Task) FillParams(target interface{}) (err error) {
content, err := json.Marshal(task.Params)
if err != nil {
return
Expand Down Expand Up @@ -159,7 +159,7 @@ func (task *Task) ValidateNewTask(template Template) error {
params = &DefaultTaskParams{}
}

return task.GetParams(params)
return task.FillParams(params)
}

func (task *TaskWithTpl) Fill(d Store) error {
Expand Down
48 changes: 31 additions & 17 deletions services/tasks/LocalJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a
}

var params db.TerraformTaskParams
err = t.Task.GetParams(&params)
err = t.Task.FillParams(&params)
if err != nil {
return
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func (t *LocalJob) getPlaybookArgs(username string, incomingVersion *string) (ar

var params db.AnsibleTaskParams

err = t.Task.GetParams(&params)
err = t.Task.FillParams(&params)
if err != nil {
return
}
Expand Down Expand Up @@ -419,6 +419,25 @@ func (t *LocalJob) getPlaybookArgs(username string, incomingVersion *string) (ar
return
}

func (t *LocalJob) getParams() (params interface{}, err error) {
switch t.Template.App {
case db.AppAnsible:
params = &db.AnsibleTaskParams{}
case db.AppTerraform, db.AppTofu:
params = &db.TerraformTaskParams{}
default:
params = &db.DefaultTaskParams{}
}

err = t.Task.FillParams(params)

if err != nil {
return
}

return
}

func (t *LocalJob) Run(username string, incomingVersion *string, alias string) (err error) {

defer func() {
Expand All @@ -433,40 +452,35 @@ func (t *LocalJob) Run(username string, incomingVersion *string, alias string) (
return
}

params, err := t.getParams()
if err != nil {
return
}

err = t.prepareRun(&environmentVariables, params)
if err != nil {
return err
}

var args []string
var inputs map[string]string
var params interface{}

switch t.Template.App {
case db.AppAnsible:
args, inputs, err = t.getPlaybookArgs(username, incomingVersion)
params = &db.AnsibleTaskParams{}
case db.AppTerraform, db.AppTofu:
args, err = t.getTerraformArgs(username, incomingVersion)
params = &db.TerraformTaskParams{}
if alias != "" {
environmentVariables = append(environmentVariables, "TF_HTTP_ADDRESS="+util.GetPublicAliasURL("terraform", alias))
}
default:
args, err = t.getShellArgs(username, incomingVersion)
params = &db.DefaultTaskParams{}
}

if err != nil {
return
}

err = t.Task.GetParams(params)

if err != nil {
return
}

err = t.prepareRun(&environmentVariables, params)
if err != nil {
return err
}

if t.Inventory.SSHKey.Type == db.AccessKeySSH && t.Inventory.SSHKeyID != nil {
environmentVariables = append(environmentVariables, fmt.Sprintf("SSH_AUTH_SOCK=%s", t.sshKeyInstallation.SSHAgent.SocketFile))
}
Expand Down

0 comments on commit d8aba18

Please sign in to comment.