feat: 简单执行ansible命令或者ansible-playbook剧本

This commit is contained in:
2025-07-03 21:18:42 +08:00
parent 3766fd5244
commit e3c26b613b
12 changed files with 458 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
package main
import (
"encoding/json"
"fmt"
"kenaito-ansible-go-example/core"
)
func main() {
testExecuteCommand()
//testExecutePlaybook()
}
func testExecuteCommand() {
command := core.ExecuteCommand(
"local",
[]string{"192.168.150.170", "192.168.205.234"},
"command",
"pingxxxx 127.0.0.1 -c 2",
nil,
)
marshal, err := json.Marshal(command)
if err != nil {
fmt.Println("Error marshalling to JSON:", err)
return
}
fmt.Printf("Execute Result: %s\n", string(marshal))
}
func testExecutePlaybook() {
command := core.ExecutePlaybook(
"local",
[]string{"192.168.150.170", "192.168.205.234"},
[]string{"site1.yml", "site2.yml", "site3.yml"},
nil,
)
marshal, err := json.Marshal(command)
if err != nil {
fmt.Println("Error marshalling to JSON:", err)
return
}
fmt.Printf("Execute Playbook Result: %s\n", string(marshal))
}