add go cli initial

This commit is contained in:
Bartal Læarsson
2025-03-01 23:46:45 +00:00
parent d92746a897
commit 32fded1754
14 changed files with 892 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package ansible
import (
"fmt"
"os"
"os/exec"
)
// RunPlaybook executes an Ansible playbook with the given inventory and extra variables
func RunPlaybook(playbook, inventory string, extraArgs []string) error {
// Check if ansible-playbook is available
if _, err := exec.LookPath("ansible-playbook"); err != nil {
return fmt.Errorf("ansible-playbook command not found: %w", err)
}
// Build the command
args := []string{"-i", inventory}
// Add any extra arguments
args = append(args, extraArgs...)
// Add the playbook at the end
args = append(args, playbook)
// Create the command
cmd := exec.Command("ansible-playbook", args...)
// Connect the command's outputs to our process's outputs
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin // Pass stdin for any prompts
// Run the command
fmt.Printf("Running: ansible-playbook %v\n", args)
return cmd.Run()
}