apenella / go-ansible

Go-ansible is a Go package that enables the execution of ansible-playbook or ansible commands directly from Golang applications. It supports a wide range of options for each command, enabling smooth integration of Ansible functionality into your projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duration + Json parsing

TheFieryLynx opened this issue · comments

if i make:

execute := execute.NewDefaultExecute(
	execute.WithWrite(io.Writer(buff)),
	execute.WithShowDuration(),
)

then:

StdoutCallback:    	"json",
Exec: 			execute,

then:

err := playbook.Run(context.TODO())
res, err = results.JSONParse(buff.Bytes())

it will be error:

panic: Unmarshall error
	invalid character 'D' after top-level value

goroutine 1 [running]:

Because of line in the end of output: "Duration: 5.348349791s"

Sorry, if it's my mistake! Amazing rep!

Hi @TheFieryLynx!
you are right, when you would like to show the duration with json stdout, it breaks the outcome json returned by ansible.
I am going to think how to be protected again it.

Thanks!

hi @TheFieryLynx
I am already working on that issue. You could check the PR #92
The idea is to remove the show duration responsibility from DefaultExecute's Execute method, and define a new method to achieve the duration.

hi @TheFieryLynx
although it does not belong to any release yet, on master branch duration time is not measured anymore inside the executor, but has been created a decorator to do that.

Thanks for raising it up!

@TheFieryLynx just to let you know, I decided to prepare the release v1.1.6 which will have that changes.
Thank you very much!

Thank you!