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

How to get ansible log as JSON?

dikkini opened this issue · comments

I've read doc but i did not understand, how to get ansible log as JSON?

	playbook := &ansibler.AnsiblePlaybookCmd{
		Playbook: fmt.Sprintf(playbookPath, "test"),
		Options:  ansiblePlaybookOptions,
		Writer:   &AnsibleLog{},
		StdoutCallback: "json",
	}

code below make a panic

panic: send on closed channel

goroutine 7 [running]:
github.com/apenella/go-ansible/execute.(*DefaultExecute).Execute.func1(0xc0001c2080, 0x0, 0x0, 0x16e5b00, 0xc0000106b0, 0xc000028840, 0xc0000287e0)
        /Users/dikkini/go/pkg/mod/github.com/apenella/go-ansible@v0.5.1/execute/defaultExecute.go:92 +0x158
created by github.com/apenella/go-ansible/execute.(*DefaultExecute).Execute
        /Users/dikkini/go/pkg/mod/github.com/apenella/go-ansible@v0.5.1/execute/defaultExecute.go:82 +0x508
Exiting.

Also, there is a misstake in example https://github.com/apenella/go-ansible/blob/master/examples/simple-ansibleplaybook-json/simple-ansibleplaybook-json.go#L41

Error: Cannot use 'buff.Bytes()' (type []byte) as type *bufio.Reader

I updated to 0.8.0 version and everything is fine. thank you :D

@dikkini I am glad to know that you could solve it!
Regarding the JSONParser error, on v0.6.0 it changed its signature and I didn't warn that it was a breaking change and I neither tagged it with a major version, sorry.