diff --git a/pkg/ansibleserver/models/ansibleplaybooks.go b/pkg/ansibleserver/models/ansibleplaybooks.go index 0ef0f61b8c..92feab89aa 100644 --- a/pkg/ansibleserver/models/ansibleplaybooks.go +++ b/pkg/ansibleserver/models/ansibleplaybooks.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/pkg/errors" "yunion.io/x/sqlchemy" + "yunion.io/x/onecloud/pkg/ansibleserver/options" "yunion.io/x/onecloud/pkg/apis" api "yunion.io/x/onecloud/pkg/apis/ansible" "yunion.io/x/onecloud/pkg/cloudcommon/db" @@ -186,10 +187,16 @@ func (apb *SAnsiblePlaybook) runPlaybook(ctx context.Context, userCred mcclient. // init private key pb := apb.Playbook.Copy() - if k, err := mcclient_modules.Sshkeypairs.FetchPrivateKey(ctx, userCred); err != nil { - return err - } else { - pb.PrivateKey = []byte(k) + if len(pb.PrivateKey) == 0 { + if k, err := mcclient_modules.Sshkeypairs.FetchPrivateKey(ctx, userCred); err != nil { + return err + } else { + pb.PrivateKey = []byte(k) + } + } + // init tmpdir clean policy + if options.Options.KeepTmpdir { + pb.CleanOnExit(false) } pb.OutputWriter(&ansiblePlaybookOutputWriter{apb}) diff --git a/pkg/ansibleserver/models/ansibleplaybooks_validator.go b/pkg/ansibleserver/models/ansibleplaybooks_validator.go index 90b2da5c84..ed9608e460 100644 --- a/pkg/ansibleserver/models/ansibleplaybooks_validator.go +++ b/pkg/ansibleserver/models/ansibleplaybooks_validator.go @@ -87,6 +87,10 @@ func (v *ValidatorAnsiblePlaybook) Validate(data *jsonutils.JSONDict) error { } } } + // add LF for privateKey + if len(pb.PrivateKey) > 0 && pb.PrivateKey[len(pb.PrivateKey)-1] != 10 { + pb.PrivateKey = append(pb.PrivateKey, 10) + } pbJson := jsonutils.Marshal(pb) if serialized := pbJson.String(); len(serialized) > PlaybookMaxBytes { return httperrors.NewBadRequestError("playbook too big, got %d bytes, exceeding %d",