55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package kubespray
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"kube-forge/internal/config"
|
|
"kube-forge/internal/logging"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/apenella/go-ansible/v2/pkg/playbook"
|
|
)
|
|
|
|
func getPlaybookParameters(tags string) playbook.AnsiblePlaybookOptions {
|
|
cfg := config.GetConfig()
|
|
|
|
ansiblePlaybookOptions := playbook.AnsiblePlaybookOptions{
|
|
Inventory: filepath.Join(cfg.InventoryDir, "hosts"),
|
|
Tags: tags,
|
|
User: cfg.Credentials.User,
|
|
Become: true,
|
|
}
|
|
|
|
if cfg.Credentials.PrivateKeyFile != "" {
|
|
ansiblePlaybookOptions.PrivateKey = cfg.Credentials.PrivateKeyFile
|
|
}
|
|
|
|
if cfg.Credentials.AskSudoPassword {
|
|
ansiblePlaybookOptions.AskBecomePass = true
|
|
}
|
|
|
|
return ansiblePlaybookOptions
|
|
}
|
|
|
|
func CopyK8SAdminConfig(outFile string) {
|
|
config := config.GetConfig()
|
|
var adminDefaultConfigPath = filepath.Join(config.InventoryDir, "artifacts/admin.conf")
|
|
source, err := os.Open(adminDefaultConfigPath)
|
|
if err != nil {
|
|
logging.Log.Fatal(err)
|
|
}
|
|
defer source.Close()
|
|
|
|
destination, err := os.Create(outFile)
|
|
if err != nil {
|
|
logging.Log.Fatal(err)
|
|
}
|
|
defer destination.Close()
|
|
_, err = io.Copy(destination, source)
|
|
if err != nil {
|
|
logging.Log.Fatal(err)
|
|
}
|
|
logging.Log.Info(fmt.Sprintf("K8s admin config: %s", outFile))
|
|
}
|