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.
MIT License
905 stars 143 forks source link

How to get success result? #59

Closed wahello closed 3 years ago

wahello commented 3 years ago

How to get success result?

apenella commented 3 years ago

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!

wahello commented 3 years ago

@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.

apenella commented 3 years ago

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

wahello commented 3 years ago

@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?.

wahello commented 3 years ago

I got it.

cyberchao commented 3 years ago

@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.

apenella commented 3 years ago

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.

wahello commented 3 years ago

@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.