mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-09 16:07:36 +08:00
Merge pull request #10932 from rainzm/sshable/fix
Correctly execute the ansible playbook with the specified private key
This commit is contained in:
@@ -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})
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user