Archived
1

first commit

This commit is contained in:
2024-12-23 01:55:48 +03:00
commit b514cc36fb
33 changed files with 1969 additions and 0 deletions

48
internal/types/hosts.go Normal file
View File

@@ -0,0 +1,48 @@
package types
import (
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"playbookctl/internal/utils"
)
var DefaultInterpreter = "/usr/bin/python3"
type THostProps struct {
Host string `yaml:"ansible_host"`
Port uint16 `yaml:"ansible_port"`
User string `yaml:"ansible_user"`
Interpreter string `yaml:"ansible_python_interpreter"`
}
type THosts map[string]THostProps
type tUngrouped struct {
Hosts THosts `yaml:"hosts"`
}
type tHostsConfig struct {
Ungrouped tUngrouped `yaml:"ungrouped"`
}
func ReadHosts(workDir string) (*THosts, error) {
var hostsConf tHostsConfig
{
bb, err := os.ReadFile(filepath.Join(workDir, "hosts.yml"))
if err != nil {
return nil, err
}
if err := yaml.Unmarshal(bb, &hostsConf); err != nil {
return nil, err
}
}
return &hostsConf.Ungrouped.Hosts, nil
}
func WriteHosts(workDir string, hosts *THosts) error {
hostsConf := tHostsConfig{Ungrouped: tUngrouped{Hosts: *hosts}}
return utils.WriteYaml(&hostsConf, filepath.Join(workDir, "hosts.yml"))
}

View File

@@ -0,0 +1,15 @@
package types
import (
"path/filepath"
"playbookctl/internal/utils"
)
type MainTask struct {
IncludeTasks string `yaml:"include_tasks"`
When string `yaml:"when"`
}
func WriteMainTask(roleDir string, mainTask *[]MainTask) error {
return utils.WriteYaml(mainTask, filepath.Join(roleDir, "tasks", "main.yml"))
}

View File

@@ -0,0 +1,40 @@
package types
import (
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"playbookctl/internal/utils"
)
type Task struct {
Name string `yaml:"name"`
IncludeVars string `yaml:"include_vars"`
}
type Playbook struct {
Hosts string `yaml:"hosts"`
GatherFacts bool `yaml:"gather_facts"`
PreTasks []Task `yaml:"pre_tasks"`
Roles []string `yaml:"roles"`
}
func ReadPlaybook(workDir string) (*Playbook, error) {
var playbook []Playbook
{
bb, err := os.ReadFile(filepath.Join(workDir, "playbook.yml"))
if err != nil {
return nil, err
}
if err := yaml.Unmarshal(bb, &playbook); err != nil {
return nil, err
}
}
return &playbook[0], nil
}
func WritePlaybook(workDir string, playbook *Playbook) error {
return utils.WriteYaml([]*Playbook{playbook}, filepath.Join(workDir, "playbook.yml"))
}