go-ansible icon indicating copy to clipboard operation
go-ansible copied to clipboard

when i use Verbose=true in playbookOptions, parsejson fail invalid character 'a' looking for beginning of value

Open YXY-121 opened this issue 3 years ago • 5 comments

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"
}

YXY-121 avatar Aug 31 '22 08:08 YXY-121

the version that i use is the lastest

YXY-121 avatar Aug 31 '22 09:08 YXY-121

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

YXY-121 avatar Aug 31 '22 09:08 YXY-121

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.

apenella avatar Sep 01 '22 05:09 apenella

hi @apenella well i am interested in it. i would like to find out the solution with u

YXY-121 avatar Sep 07 '22 02:09 YXY-121

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.

apenella avatar Jun 25 '23 14:06 apenella

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!

apenella avatar Apr 10 '24 20:04 apenella

The fix is available in https://github.com/apenella/go-ansible/releases/tag/v2.0.0

apenella avatar Apr 20 '24 15:04 apenella