Skip to content

daixijun/go-salt

Repository files navigation

Go SaltStack

go 调用 salt-api 接口

安装

go get github.com/daixijun/go-salt

使用

package main

import (
	"context"
	"fmt"

	salt "github.com/daixijun/go-salt/v2"
)

func main() {

	ctx := context.TODO()
	// 初始化客户端
	client := salt.NewClient(
		salt.WithEndpoint("https://saltapi.example.com"),
		salt.WithUsername("saltapi"),
		salt.WithPassword("saltapi"),
		salt.WithAuthBackend("pam"),
		salt.WithInsecure(),
	)
	if err := client.Login(ctx); err != nil {
		panic(err)
	}

	// 列表 minions
	minions, err := client.ListMinions(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println(minions)

	// 执行命令
	resp, err := client.LocalClient(ctx, "cmd.run", []string{"whoami"}, salt.WithGlobTarget("minion1"))
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}

支持的接口

About

Golang saltstack sdk

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages