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 success result?

wahello opened this issue · comments

commented

How to get success result?

HI @wahello
could you extend you question or give some more context, please?
Folder https://github.com/apenella/go-ansible/tree/master/examples has several examples where you could see how to manage Ansible results.

Thanks!

commented

@apenella Like executing builtin module setup, if successful, how to obtain the hardware info of the results in code? The result is printed in log.

Hi @wahello!
go-ansible executes ansible commands. To achieve setup's module results you need to update ansible playbook to do that. You could do it using ansible's debug module.

Let me know if you have any update!
Thanks

commented

@apenella I must missed something. How to get the print log, excuting this line
err := adhoc.Run(context.TODO()) in examples
when err is nil?.

commented

I got it.

commented

@apenella I must missed something. How to get the print log, excuting this line
err := adhoc.Run(context.TODO()) in examples
when err is nil?.

hi, Have you found a solution?i need to get adhoc result also.

Hi! @cyberchao
by default, when you run an ad hoc command, its output is printed to stdout.

In case you would manage the output, such as is done when you use json stdout callback, you need to create your own executor and store the command output to a buffer.
Take a look at that example:
https://github.com/apenella/go-ansible/blob/master/examples/json-stdout-ansibleplaybook/json-stdout-ansibleplaybook.go#L31

I hope it could help you! Let me know if you need anything else.

commented

@apenella Exactly!

Hi! @cyberchao
by default, when you run an ad hoc command, its output is printed to stdout.

In case you would manage the output, such as is done when you use json stdout callback, you need to create your own executor and store the command output to a buffer.
Take a look at that example:
https://github.com/apenella/go-ansible/blob/master/examples/json-stdout-ansibleplaybook/json-stdout-ansibleplaybook.go#L31

I hope it could help you! Let me know if you need anything else.