diff --git a/provisioner/ansible/adapter.go b/provisioner/ansible/adapter.go index 62cf54c60..9458e4117 100644 --- a/provisioner/ansible/adapter.go +++ b/provisioner/ansible/adapter.go @@ -52,6 +52,7 @@ func (c *adapter) Serve() { conn, err := c.l.Accept() select { case <-c.done: + close(errc) return default: if err != nil { @@ -62,8 +63,6 @@ func (c *adapter) Serve() { }(conn) } } - - close(errc) } func (c *adapter) Handle(conn net.Conn, errc chan<- error) error { @@ -83,9 +82,9 @@ func (c *adapter) Handle(conn net.Conn, errc chan<- error) error { continue } - go func(errc chan<- error) { - errc <- c.handleSession(newChannel) - }(errc) + go func(errc chan<- error, ch ssh.NewChannel) { + errc <- c.handleSession(ch) + }(errc, newChannel) } return nil diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 063c9334e..acfb961b6 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -115,8 +115,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { keyChecker := ssh.CertChecker{ UserKeyFallback: func(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) { - if conn.User() != "packer-ansible" { - ui.Say(fmt.Sprintf("%s is not a valid user")) + if user := conn.User(); user != "packer-ansible" { + ui.Say(fmt.Sprintf("%s is not a valid user", user)) return nil, errors.New("authentication failed") }