Commit 556691ac authored by 魏灿's avatar 魏灿

脚本实时输出返回

parent feb21ce5
package service
import (
"bufio"
"context"
"errors"
"fmt"
......@@ -186,7 +187,7 @@ func (t *TaskManageSvc) ListTaskManage(req request.ListTaskManageReq) (total int
return
}
func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{}, err error) {
func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]interface{}, err error) {
if req.ScriptUrl != "" {
minioClient, err := client.GetMinioConnect()
if err != nil {
......@@ -251,11 +252,19 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
} else {
cmd = exec.Command("ansible-playbook", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml")
}
output, err := cmd.Output()
stdout, err := cmd.StdoutPipe()
if err != nil {
err = resp.CmdExecError.WithError(err)
return
return nil, resp.CmdExecError.WithError(err)
}
fmt.Println(string(output))
return string(output), nil
outputBuf := bufio.NewReader(stdout)
output, isPrefix, err := outputBuf.ReadLine()
//output, err := cmd.Output()
//if err != nil {
// err = resp.CmdExecError.WithError(err)
// return
//}
//fmt.Println(string(output))
data["step"] = isPrefix
data["output"] = string(output)
return data, 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