Commit 083522e1 authored by 陈子龙's avatar 陈子龙

立即执行逻辑优化 fix

parent a91d9f4e
...@@ -227,24 +227,26 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id ...@@ -227,24 +227,26 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
for _, v := range hostManageList { for _, v := range hostManageList {
hostsIp := "" hostsIp := ""
if v.VoucherType == 0 { if v.VoucherType == 0 {
hostsIp = fmt.Sprintf("%s:%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\" ansible_host_key_checking=false\n", hostsIp = fmt.Sprintf("%s:%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\" ansible_host_key_checking=false",
v.Ip, v.Port, v.UserName, v.Password) v.Ip, v.Port, v.UserName, v.Password)
} else { } else {
hostsIp = fmt.Sprintf("%s:%s ansible_ssh_user=\"%s\" ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false\n", hostsIp = fmt.Sprintf("%s:%s ansible_ssh_user=\"%s\" ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false",
v.Ip, v.Port, v.UserName) v.Ip, v.Port, v.UserName)
} }
hosts = append(hosts, hostsIp) hosts = append(hosts, hostsIp)
} }
//写入主机信息 //写入主机信息
hostsIp := strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", "\n", -1)
//hostsIp := strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", " ", -1)
hostsGroup, err := os.Create("/etc/ansible/hosts_" + fmt.Sprintf("%d", req.TaskId)) hostsGroup, err := os.Create("/etc/ansible/hosts_" + fmt.Sprintf("%d", req.TaskId))
if err != nil { if err != nil {
err = resp.FileExecError.WithError(err) err = resp.FileExecError.WithError(err)
return return
} }
defer hostsGroup.Close() defer hostsGroup.Close()
_, err = hostsGroup.Write([]byte(hostsIp)) //_, err = hostsGroup.Write([]byte(hostsIp))
_, err = hostsGroup.Write([]byte(strings.Join(hosts, "\n")))
if err != nil { if err != nil {
err = resp.FileExecError.WithError(err) err = resp.FileExecError.WithError(err)
return return
......
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