diff --git a/command/commands.go b/command/commands.go index d79e3a7..77a721c 100644 --- a/command/commands.go +++ b/command/commands.go @@ -59,3 +59,16 @@ func Ping(ip string) *cmd { } } } + +func AnsiblePlaybook(ip string, playbook string) *cmd { + return &cmd{ + command: "ansible-playbook", + args: []string{ + "-i", ip + ",", + "-e", "ansible_user=" + db.Username, + "-e", "ansible_private_key_file=" + db.PrivateKeyPath, + "--ssh-common-args", "-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null", + playbook, + }, + } +} diff --git a/vms/create.go b/vms/create.go index c5733b6..341ac54 100644 --- a/vms/create.go +++ b/vms/create.go @@ -63,6 +63,7 @@ func Create(imageName string, ps ProvisionScript, cpus int, mem int) (string, er } if len(ps.Script) > 0 { + fmt.Println("Provisioning", vmName) if err := ps.Func(vmName, ps.Script); err != nil { return "", err } diff --git a/vms/provision.go b/vms/provision.go index cbcb410..03c8a5d 100644 --- a/vms/provision.go +++ b/vms/provision.go @@ -1,14 +1,14 @@ package vms import ( - "fmt" + "github.com/mhewedy/vermin/command" "github.com/mhewedy/vermin/command/scp" "github.com/mhewedy/vermin/command/ssh" + "github.com/mhewedy/vermin/ip" "path/filepath" ) func ProvisionShell(vmName string, script string) error { - fmt.Println("Provisioning", vmName) vmFile := "/tmp/" + filepath.Base(script) if err := scp.CopyToVM(vmName, script, vmFile); err != nil { @@ -26,7 +26,10 @@ func ProvisionShell(vmName string, script string) error { func ProvisionAnsible(vmName string, script string) error { - // TODO add ansbile provisionShell processing + ipAddr, err := ip.Find(vmName, false) + if err != nil { + return err + } - return nil + return command.AnsiblePlaybook(ipAddr, script).Interact() }