Commit 377d6b11 authored by 魏灿's avatar 魏灿

文件权限写入fix

parent 499711b4
......@@ -156,7 +156,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
return nil, resp.DbSelectError.WithError(err)
}
//写入主机组ip
f, err := os.Open("/etc/ansible/hosts")
f, err := os.OpenFile("/etc/ansible/hosts", os.O_APPEND|os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
if err != nil {
err = resp.FileExecError.WithError(err)
return
......@@ -192,7 +192,12 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
}
req.Value = fmt.Sprintf("@/etc/ansible/ansible_extra.yml")
}
cmd := exec.Command("ansible", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml", "--extra-vars", req.Value)
var cmd *exec.Cmd
if req.Value != "" {
cmd = exec.Command("ansible", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml", "--extra-vars", req.Value)
} else {
cmd = exec.Command("ansible", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml")
}
output, err := cmd.Output()
if err != nil {
err = resp.CmdExecError.WithError(err)
......
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