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
This commit is contained in:
Rickard von Essen 2016-11-05 14:25:45 +01:00
parent 233913bc38
commit a616c3da3c
No known key found for this signature in database
GPG Key ID: E0C0327388876CBA
2 changed files with 9 additions and 11 deletions

View File

@ -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)
}
}

View File

@ -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()