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.
This commit is contained in:
Mario Steinhoff 2016-02-27 07:20:54 +01:00
parent b199a6e546
commit b5f6e379f0
1 changed files with 16 additions and 6 deletions

View File

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