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:
parent
b199a6e546
commit
b5f6e379f0
|
@ -20,6 +20,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
|
||||||
|
@ -327,12 +328,21 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
repeat := func(r io.ReadCloser) {
|
repeat := func(r io.ReadCloser) {
|
||||||
scanner := bufio.NewScanner(r)
|
reader := bufio.NewReader(r)
|
||||||
for scanner.Scan() {
|
for {
|
||||||
ui.Message(scanner.Text())
|
line, err := reader.ReadString('\n')
|
||||||
|
if line != "" {
|
||||||
|
line = strings.TrimRightFunc(line, unicode.IsSpace)
|
||||||
|
ui.Message(line)
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue