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

hosts fix

parent 03a71f3a
...@@ -36,5 +36,6 @@ type ExecScriptReq struct { ...@@ -36,5 +36,6 @@ type ExecScriptReq struct {
HostGroupId int `form:"host_group_id" vd:"$>0;msg:'请输入主机分组id'"` //主机分组id HostGroupId int `form:"host_group_id" vd:"$>0;msg:'请输入主机分组id'"` //主机分组id
Type int `form:"type"` //脚本额外变量类型1yaml 2json Type int `form:"type"` //脚本额外变量类型1yaml 2json
Value string `form:"value"` //脚本额外变量值 Value string `form:"value"` //脚本额外变量值
Script string `form:"script"` //执行脚本 ExecType int `form:"exec_type" binding:"oneof=1 2"` //执行类型:1文本执行 2文件执行
Script string `form:"script"` //执行脚本/文件名
} }
...@@ -123,6 +123,10 @@ func ExecScript(c *gin.Context) { ...@@ -123,6 +123,10 @@ func ExecScript(c *gin.Context) {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
} }
if req.Type == 2 {
//从minio读取yaml文件
}
taskManageSvc := service.TaskManageSvc{} taskManageSvc := service.TaskManageSvc{}
data, err := taskManageSvc.ExecScript(req) data, err := taskManageSvc.ExecScript(req)
if err != nil { if err != nil {
......
...@@ -416,12 +416,24 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL ...@@ -416,12 +416,24 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
} }
//往hosts文件中写入主机组ip //往hosts文件中写入主机组ip
f, err := os.Open("/etc/ansible/hosts") //f, err := os.Open("/etc/ansible/hosts")
//if err != nil {
// err = resp.FileExecError.WithError(err)
// return
//}
//defer f.Close()
f, err := os.OpenFile("/etc/ansible/hosts", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0777)
if err != nil { if err != nil {
err = resp.FileExecError.WithError(err) err = resp.FileExecError.WithError(err)
return return
} }
defer f.Close() defer f.Close()
//_, err = f.Write([]byte(fmt.Sprintf("%s%d\n", AnsibleGroup, req.Id)))
//if err != nil {
// err = resp.FileExecError.WithError(err)
// return
//}
for _, v := range hostManageList { for _, v := range hostManageList {
_, err = f.Write([]byte(fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\"\n", v.Ip, v.Ip, v.Port, v.UserName, v.Password))) _, err = f.Write([]byte(fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\"\n", v.Ip, v.Ip, v.Port, v.UserName, v.Password)))
if err != nil { if err != nil {
...@@ -432,10 +444,6 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL ...@@ -432,10 +444,6 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
//状态检测 //状态检测
id = uuid.New().String() id = uuid.New().String()
if err != nil {
err = resp.FAIL.WithError(err)
return
}
for k, v := range HostManageListCaches { for k, v := range HostManageListCaches {
//调用状态检测函数 //调用状态检测函数
HostManageListCaches[k].ConnStatus = StatusDetection(v.Ip) HostManageListCaches[k].ConnStatus = StatusDetection(v.Ip)
......
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