2019-04-15 17:22:25 -04:00
|
|
|
package linode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-07-02 16:56:28 -04:00
|
|
|
"log"
|
2019-04-15 17:22:25 -04:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
|
|
"github.com/linode/linodego"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
)
|
|
|
|
|
2019-07-02 16:56:28 -04:00
|
|
|
func commHost(host string) func(multistep.StateBag) (string, error) {
|
|
|
|
return func(state multistep.StateBag) (string, error) {
|
|
|
|
if host != "" {
|
|
|
|
log.Printf("Using ssh_host value: %s", host)
|
|
|
|
return host, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
instance := state.Get("instance").(*linodego.Instance)
|
|
|
|
if len(instance.IPv4) == 0 {
|
|
|
|
return "", fmt.Errorf("Linode instance %d has no IPv4 addresses!", instance.ID)
|
|
|
|
}
|
|
|
|
return instance.IPv4[0].String(), nil
|
2019-04-15 17:22:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
|
|
|
return &ssh.ClientConfig{
|
|
|
|
User: "root",
|
|
|
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.Password(state.Get("root_pass").(string)),
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|