From b5f6e379f06930006d9c714e17edc622b1840adf Mon Sep 17 00:00:00 2001 From: Mario Steinhoff Date: Sat, 27 Feb 2016 07:20:54 +0100 Subject: [PATCH] Fix Scanner buffer too long error in ansible-remote provisioner Ansible may produce very long lines which Scanner can not handle. This replaces the Scanner with a Reader and uses the ReadString method to read an arbitrary large line from the ansible-playbook stdout pipe. --- provisioner/ansible/provisioner.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index e38e4bc08..d7a4be655 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -20,6 +20,7 @@ import ( "strconv" "strings" "sync" + "unicode" "golang.org/x/crypto/ssh" @@ -327,12 +328,21 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri wg := sync.WaitGroup{} repeat := func(r io.ReadCloser) { - scanner := bufio.NewScanner(r) - for scanner.Scan() { - ui.Message(scanner.Text()) - } - if err := scanner.Err(); err != nil { - ui.Error(err.Error()) + reader := bufio.NewReader(r) + for { + line, err := reader.ReadString('\n') + if line != "" { + line = strings.TrimRightFunc(line, unicode.IsSpace) + ui.Message(line) + } + if err != nil { + if err == io.EOF { + break + } else { + ui.Error(err.Error()) + break + } + } } wg.Done() }