Commit 5e1c7983 authored by 陈子龙's avatar 陈子龙

自动化运维 立即执行 fix

parent b88731d2
......@@ -5,8 +5,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ghodss/yaml"
json "github.com/json-iterator/go"
"github.com/minio/minio-go/v7"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
......@@ -203,27 +201,27 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
}
req.Script = string(obj)
}
var scripts []map[string]interface{}
var script map[string]interface{}
j2, err := yaml.YAMLToJSON([]byte(req.Script))
if err != nil {
return nil, resp.YamlAnalysisError.WithError(err)
}
err = json.Unmarshal(j2, &scripts)
if err != nil {
return nil, resp.MarshalError.WithError(errors.New("yaml格式错误"))
}
script = scripts[0]
script["host"] = fmt.Sprintf("%s%d", AnsibleGroup, req.HostGroupId)
j, err := json.Marshal(script)
if err != nil {
return nil, resp.MarshalError.WithError(err)
}
y, err := yaml.JSONToYAML(j)
if err != nil {
return nil, resp.YamlAnalysisError.WithError(err)
}
req.Script = string(y)
//var scripts []map[string]interface{}
//var script map[string]interface{}
//j2, err := yaml.YAMLToJSON([]byte(req.Script))
//if err != nil {
// return nil, resp.YamlAnalysisError.WithError(err)
//}
//err = json.Unmarshal(j2, &scripts)
//if err != nil {
// return nil, resp.MarshalError.WithError(errors.New("yaml格式错误"))
//}
//script = scripts[0]
//script["host"] = fmt.Sprintf("%s%d", AnsibleGroup, req.HostGroupId)
//j, err := json.Marshal(script)
//if err != nil {
// return nil, resp.MarshalError.WithError(err)
//}
//y, err := yaml.JSONToYAML(j)
//if err != nil {
// return nil, resp.YamlAnalysisError.WithError(err)
//}
//req.Script = string(y)
//写入执行脚本
f2, err := os.Create("/etc/ansible/ansible.yml")
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment