Commit 79150d86 authored by 魏灿's avatar 魏灿

form yml解析

parent ca1f3688
...@@ -32,8 +32,8 @@ type ListTaskManageReq struct { ...@@ -32,8 +32,8 @@ type ListTaskManageReq struct {
} }
type ExecScriptReq struct { type ExecScriptReq struct {
HostGroupId int `json:"host_group_id" vd:"$>0;msg:'请输入主机分组id'"` //主机分组id HostGroupId int `form:"host_group_id" vd:"$>0;msg:'请输入主机分组id'"` //主机分组id
Type int `json:"type"` //脚本额外变量类型1yaml 2json Type int `form:"type"` //脚本额外变量类型1yaml 2json
Value string `json:"value"` //脚本额外变量值 Value string `form:"value"` //脚本额外变量值
Script string `json:"script"` //执行脚本 Script string `form:"script"` //执行脚本
} }
...@@ -119,12 +119,7 @@ func ListTaskManage(c *gin.Context) { ...@@ -119,12 +119,7 @@ func ListTaskManage(c *gin.Context) {
func ExecScript(c *gin.Context) { func ExecScript(c *gin.Context) {
var req request.ExecScriptReq var req request.ExecScriptReq
if err := c.ShouldBindJSON(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
//参数校验
if err := util.ValidateSimple(req, "HostManageId"); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
} }
......
...@@ -194,9 +194,9 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{}, ...@@ -194,9 +194,9 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
} }
var cmd *exec.Cmd var cmd *exec.Cmd
if req.Value != "" { if req.Value != "" {
cmd = exec.Command("ansible", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml", "--extra-vars", req.Value) cmd = exec.Command("ansible-playbook", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml", "--extra-vars", req.Value)
} else { } else {
cmd = exec.Command("ansible", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml") cmd = exec.Command("ansible-playbook", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml")
} }
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { 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