Skip to content

Commit

Permalink
fix #9 support ansible provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Aug 8, 2020
1 parent 5fe3ce2 commit 8f37360
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
1 change: 1 addition & 0 deletions vms/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions vms/provision.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
}

0 comments on commit 8f37360

Please sign in to comment.