Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
c2c1f951
Commit
c2c1f951
authored
Jul 03, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hosts fix
parent
03a71f3a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
6 deletions
+19
-6
src/bean/vo/request/task_manage.go
src/bean/vo/request/task_manage.go
+2
-1
src/controller/task_manage.go
src/controller/task_manage.go
+4
-0
src/service/host_manage.go
src/service/host_manage.go
+13
-5
No files found.
src/bean/vo/request/task_manage.go
View file @
c2c1f951
...
...
@@ -36,5 +36,6 @@ type ExecScriptReq struct {
HostGroupId
int
`form:"host_group_id" vd:"$>0;msg:'请输入主机分组id'"`
//主机分组id
Type
int
`form:"type"`
//脚本额外变量类型1yaml 2json
Value
string
`form:"value"`
//脚本额外变量值
Script
string
`form:"script"`
//执行脚本
ExecType
int
`form:"exec_type" binding:"oneof=1 2"`
//执行类型:1文本执行 2文件执行
Script
string
`form:"script"`
//执行脚本/文件名
}
src/controller/task_manage.go
View file @
c2c1f951
...
...
@@ -123,6 +123,10 @@ func ExecScript(c *gin.Context) {
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
}
if
req
.
Type
==
2
{
//从minio读取yaml文件
}
taskManageSvc
:=
service
.
TaskManageSvc
{}
data
,
err
:=
taskManageSvc
.
ExecScript
(
req
)
if
err
!=
nil
{
...
...
src/service/host_manage.go
View file @
c2c1f951
...
...
@@ -416,12 +416,24 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
}
//往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
{
err
=
resp
.
FileExecError
.
WithError
(
err
)
return
}
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
{
_
,
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
{
...
...
@@ -432,10 +444,6 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
//状态检测
id
=
uuid
.
New
()
.
String
()
if
err
!=
nil
{
err
=
resp
.
FAIL
.
WithError
(
err
)
return
}
for
k
,
v
:=
range
HostManageListCaches
{
//调用状态检测函数
HostManageListCaches
[
k
]
.
ConnStatus
=
StatusDetection
(
v
.
Ip
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment