Commit c0f21773 authored by 陈子龙's avatar 陈子龙

自动化运维 立即执行

parent 8cb7bac1
...@@ -203,15 +203,17 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i ...@@ -203,15 +203,17 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
} }
req.Script = string(obj) req.Script = string(obj)
} }
var scripts []map[string]interface{}
var script map[string]interface{} var script map[string]interface{}
j2, err := yaml.YAMLToJSON([]byte(req.Script)) j2, err := yaml.YAMLToJSON([]byte(req.Script))
if err != nil { if err != nil {
return nil, resp.YamlAnalysisError.WithError(err) return nil, resp.YamlAnalysisError.WithError(err)
} }
err = json.Unmarshal(j2, &script) err = json.Unmarshal(j2, &scripts)
if err != nil { if err != nil {
return nil, resp.MarshalError.WithError(errors.New("yaml格式错误")) return nil, resp.MarshalError.WithError(errors.New("yaml格式错误"))
} }
script = scripts[0]
script["host"] = fmt.Sprintf("%s%d", AnsibleGroup, req.HostGroupId) script["host"] = fmt.Sprintf("%s%d", AnsibleGroup, req.HostGroupId)
j, err := json.Marshal(script) j, err := json.Marshal(script)
if err != nil { if err != nil {
...@@ -254,6 +256,8 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i ...@@ -254,6 +256,8 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
} }
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
fmt.Println("执行出错:", err)
fmt.Println("stdout:", stdout)
return nil, resp.CmdExecError.WithError(err) return nil, resp.CmdExecError.WithError(err)
} }
outputBuf := bufio.NewReader(stdout) outputBuf := bufio.NewReader(stdout)
......
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