feat: 1) ListGroups返回组内主机详细信息 2) 前端刷新间隔改为5分钟 3) 命令执行和Playbook页面主机组支持展开显示组内主机
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config 配置
|
||||
type Config struct {
|
||||
AnsiblePath string `yaml:"ansible_path"`
|
||||
InventoryDir string `yaml:"inventory_dir"`
|
||||
PlaybookDir string `yaml:"playbook_dir"`
|
||||
LogDir string `yaml:"log_dir"`
|
||||
SSHTimeout int `yaml:"ssh_timeout"`
|
||||
MaxParallelism int `yaml:"max_parallelism"`
|
||||
CallbackPlugin string `yaml:"callback_plugin"`
|
||||
}
|
||||
|
||||
// DefaultConfig 默认配置
|
||||
func DefaultConfig() *Config {
|
||||
home, _ := os.UserHomeDir()
|
||||
return &Config{
|
||||
AnsiblePath: "/usr/bin/ansible",
|
||||
InventoryDir: filepath.Join(home, "ansible-deploy/inventory"),
|
||||
PlaybookDir: filepath.Join(home, "ansible-deploy/playbooks"),
|
||||
LogDir: filepath.Join(home, "ansible-deploy/logs"),
|
||||
SSHTimeout: 30,
|
||||
MaxParallelism: 10,
|
||||
CallbackPlugin: "json",
|
||||
}
|
||||
}
|
||||
|
||||
// LoadConfig 加载配置文件
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return DefaultConfig(), err
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if cfg.AnsiblePath == "" {
|
||||
cfg.AnsiblePath = "/usr/bin/ansible"
|
||||
}
|
||||
if cfg.InventoryDir == "" {
|
||||
cfg.InventoryDir = filepath.Join(os.Getenv("HOME"), "ansible-deploy/inventory")
|
||||
}
|
||||
if cfg.PlaybookDir == "" {
|
||||
cfg.PlaybookDir = filepath.Join(os.Getenv("HOME"), "ansible-deploy/playbooks")
|
||||
}
|
||||
if cfg.LogDir == "" {
|
||||
cfg.LogDir = filepath.Join(os.Getenv("HOME"), "ansible-deploy/logs")
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user