From a616c3da3ccb05c2adcc2b6a454e78098ef9afac Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Sat, 5 Nov 2016 14:25:45 +0100 Subject: [PATCH] provisioner/ansible: Move info messages to log Make the ansible provisioner less noisy by moving most messages to the log instead of ui print outs. Closes #4117 --- provisioner/ansible/adapter.go | 8 ++++---- provisioner/ansible/provisioner.go | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/provisioner/ansible/adapter.go b/provisioner/ansible/adapter.go index 0eb6bcda4..2c622ef1d 100644 --- a/provisioner/ansible/adapter.go +++ b/provisioner/ansible/adapter.go @@ -37,7 +37,7 @@ func newAdapter(done <-chan struct{}, l net.Listener, config *ssh.ServerConfig, } func (c *adapter) Serve() { - c.ui.Say(fmt.Sprintf("SSH proxy: serving on %s", c.l.Addr())) + log.Printf("SSH proxy: serving on %s", c.l.Addr()) for { // Accept will return if either the underlying connection is closed or if a connection is made. @@ -62,7 +62,7 @@ func (c *adapter) Serve() { } func (c *adapter) Handle(conn net.Conn, ui packer.Ui) error { - c.ui.Message("SSH proxy: accepted connection") + log.Print("SSH proxy: accepted connection") _, chans, reqs, err := ssh.NewServerConn(conn, c.config) if err != nil { return errors.New("failed to handshake") @@ -160,7 +160,7 @@ func (c *adapter) handleSession(newChannel ssh.NewChannel) error { sftpCmd = "/usr/lib/sftp-server -e" } - c.ui.Say("starting sftp subsystem") + log.Print("starting sftp subsystem") go func() { _ = c.remoteExec(sftpCmd, channel, channel, channel.Stderr()) close(done) @@ -171,7 +171,7 @@ func (c *adapter) handleSession(newChannel ssh.NewChannel) error { req.Reply(false, nil) } default: - c.ui.Message(fmt.Sprintf("rejecting %s request", req.Type)) + log.Printf("rejecting %s request", req.Type) req.Reply(false, nil) } } diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 97623dda7..b57edd829 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -184,13 +184,11 @@ 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 user := conn.User(); user != p.config.User { - ui.Say(fmt.Sprintf("%s is not a valid user", user)) - return nil, errors.New("authentication failed") + return nil, errors.New(fmt.Sprintf("authentication failed: %s is not a valid user", user)) } if !bytes.Equal(k.Marshal(), pubKey.Marshal()) { - ui.Say("unauthorized key") - return nil, errors.New("authentication failed") + return nil, errors.New("authentication failed: unauthorized key") } return nil, nil @@ -199,7 +197,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { 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)) + log.Printf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method) }, PublicKeyCallback: keyChecker.Authenticate, //NoClientAuth: true, @@ -242,7 +240,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { p.adapter = newAdapter(p.done, localListener, config, p.config.SFTPCmd, ui, comm) defer func() { - ui.Say("shutting down the SSH proxy") + log.Print("shutting down the SSH proxy") close(p.done) p.adapter.Shutdown() }() @@ -355,7 +353,7 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri go repeat(stdout) go repeat(stderr) - ui.Say(fmt.Sprintf("Executing Ansible: %s", strings.Join(cmd.Args, " "))) + log.Printf("Executing Ansible: %s", strings.Join(cmd.Args, " ")) cmd.Start() wg.Wait() err = cmd.Wait()