|
|
|
|
@ -111,17 +111,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|
|
|
|
|
|
|
|
|
type Keys struct {
|
|
|
|
|
//! This is the public key that we will allow to authenticate
|
|
|
|
|
public ssh.PublicKey
|
|
|
|
|
public ssh.PublicKey
|
|
|
|
|
|
|
|
|
|
//! This is the name of the file of the private key that coorlates
|
|
|
|
|
//the the public key
|
|
|
|
|
filename string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! This is the servers private key ( Set in case the public key
|
|
|
|
|
//is autogenerated )
|
|
|
|
|
private ssh.Signer
|
|
|
|
|
//is autogenerated )
|
|
|
|
|
private ssh.Signer
|
|
|
|
|
|
|
|
|
|
//! This is the flag to say the server key was generated
|
|
|
|
|
//! This is the flag to say the server key was generated
|
|
|
|
|
generated bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -133,7 +133,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|
|
|
|
var private ssh.Signer
|
|
|
|
|
var filename string = ""
|
|
|
|
|
var generated bool = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(pubKeyFile) > 0 {
|
|
|
|
|
pubKeyBytes, err := ioutil.ReadFile(pubKeyFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@ -177,7 +177,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|
|
|
|
filename = tf.Name()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(privKeyFile) > 0 {
|
|
|
|
|
if len(privKeyFile) > 0 {
|
|
|
|
|
privateBytes, err := ioutil.ReadFile(privKeyFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.New("Failed to load private host key")
|
|
|
|
|
@ -192,14 +192,14 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.New("Failed to generate server key pair")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private, err = ssh.NewSignerFromKey(key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.New("Failed to extract private key from generated key pair")
|
|
|
|
|
}
|
|
|
|
|
generated = true
|
|
|
|
|
}
|
|
|
|
|
return &Keys { public, filename, private, generated },nil
|
|
|
|
|
return &Keys{public, filename, private, generated}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
k, err := keyFactory(p.config.SSHAuthorizedKeyFile, p.config.SSHHostKeyFile)
|
|
|
|
|
@ -227,7 +227,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|
|
|
|
return nil, nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config := &ssh.ServerConfig{
|
|
|
|
|
AuthLogCallback: func(conn ssh.ConnMetadata, method string, err error) {
|
|
|
|
|
ui.Say(fmt.Sprintf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method))
|
|
|
|
|
@ -321,20 +321,20 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, aut
|
|
|
|
|
playbook, _ := filepath.Abs(p.config.PlaybookFile)
|
|
|
|
|
inventory := p.config.inventoryFile
|
|
|
|
|
|
|
|
|
|
args := []string{playbook, "-i", inventory }
|
|
|
|
|
args := []string{playbook, "-i", inventory}
|
|
|
|
|
if len(authToken) > 0 {
|
|
|
|
|
args = append(args,"--private-key",authToken)
|
|
|
|
|
args = append(args, "--private-key", authToken)
|
|
|
|
|
}
|
|
|
|
|
args = append(args, p.config.ExtraArguments...)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(p.config.Command, args...)
|
|
|
|
|
|
|
|
|
|
// If we have autogenerated the key files turn off host key checking
|
|
|
|
|
if generated {
|
|
|
|
|
cmd.Env = os.Environ()
|
|
|
|
|
cmd.Env = append(cmd.Env,"ANSIBLE_HOST_KEY_CHECKING=False")
|
|
|
|
|
cmd.Env = append(cmd.Env, "ANSIBLE_HOST_KEY_CHECKING=False")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
|