From cad24302d830e341f9d68bde432756c5a80fe4bd Mon Sep 17 00:00:00 2001 From: rainzm Date: Mon, 26 Apr 2021 18:53:07 +0800 Subject: [PATCH 1/3] fix(ansibleserver): don't init privateKey for ansibleplaybook if it already have one --- pkg/ansibleserver/models/ansibleplaybooks.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/ansibleserver/models/ansibleplaybooks.go b/pkg/ansibleserver/models/ansibleplaybooks.go index 0ef0f61b8c..dfbdcfcd47 100644 --- a/pkg/ansibleserver/models/ansibleplaybooks.go +++ b/pkg/ansibleserver/models/ansibleplaybooks.go @@ -186,10 +186,12 @@ 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) + } } pb.OutputWriter(&ansiblePlaybookOutputWriter{apb}) From 0894df5e14767d1a3137678c9eb45400b4883687 Mon Sep 17 00:00:00 2001 From: rainzm Date: Mon, 26 Apr 2021 18:56:08 +0800 Subject: [PATCH 2/3] feat(ansibleserver): respect keepTmpdir when running ansibleplaybook v1 --- pkg/ansibleserver/models/ansibleplaybooks.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/ansibleserver/models/ansibleplaybooks.go b/pkg/ansibleserver/models/ansibleplaybooks.go index dfbdcfcd47..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" @@ -193,6 +194,10 @@ func (apb *SAnsiblePlaybook) runPlaybook(ctx context.Context, userCred mcclient. pb.PrivateKey = []byte(k) } } + // init tmpdir clean policy + if options.Options.KeepTmpdir { + pb.CleanOnExit(false) + } pb.OutputWriter(&ansiblePlaybookOutputWriter{apb}) _, err := db.Update(apb, func() error { From 0d1f54bab105f20ee79759def54d6444f09ab414 Mon Sep 17 00:00:00 2001 From: rainzm Date: Mon, 26 Apr 2021 18:56:46 +0800 Subject: [PATCH 3/3] fix(ansibleserver): add LF for privateKey if not --- pkg/ansibleserver/models/ansibleplaybooks_validator.go | 4 ++++ 1 file changed, 4 insertions(+) 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",