go-ansible
go-ansible copied to clipboard
when i use Verbose=true in playbookOptions, parsejson fail invalid character 'a' looking for beginning of value
when i use “Verbose: true ” in playbook.AnsiblePlaybookOptions,output could not be parsed to result.AnsiblePlaybookJSONResult struct and err:invalid character 'a' looking for beginning of value but if i set “Verbose: false ”,the json parse ok. can u help me?thank u very much!
ansiblePlaybookConnectionOptions := &options.AnsibleConnectionOptions{
Connection: "local",
}
ansiblePlaybookOptions := &playbook.AnsiblePlaybookOptions{
Inventory: "127.0.0.1,", //
Verbose: true,
}
playbook := &playbook.AnsiblePlaybookCmd{
Exec: execute,
Playbooks: []string{"site1.yml"},
ConnectionOptions: ansiblePlaybookConnectionOptions,
Options: ansiblePlaybookOptions,
StdoutCallback: "json",
}
err := playbook.Run(context.TODO())
if err != nil {
panic(err)
}
var res *results.AnsiblePlaybookJSONResults
res, err = results.ParseJSONResultsStream(io.Reader(buff))
if err != nil {
panic(err)// this wil show"invalid character 'a' looking for beginning of value"
}
the version that i use is the lastest
oh i know the reason. when use verbose,the buff not only contains the json struct value,the buff contains something detail about the playbook ,they are not json struct
Hi @YXY-121 Thanks for raising that issue, I was not aware about it. The reason is exactly what you said :)
I would like to think a solution in depth, no just to solve that issue but how to set some restrictions depending on the stdout callback.
hi @apenella well i am interested in it. i would like to find out the solution with u
Hi @YXY-121 I want to add some breaking changes to the Executor interface which will facilitate introducing the changes I want to add to solve that issue. For that reason, I will add it to version 2.0.0.
I am about to start working on 1.2.0 where I want to release a few minor features, and as soon as I release them I am going to start working on 2.0.0.
hi @YXY-121!
I already have the fix for the issue you raised. It will be released in the coming days. https://github.com/apenella/go-ansible/pull/147/commits/9a384e5e80d4c8b3bfc2d794259c21c75907b89f
Thanks!
The fix is available in https://github.com/apenella/go-ansible/releases/tag/v2.0.0