Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get success result? #59

Closed
wahello opened this issue Jun 24, 2021 · 8 comments
Closed

How to get success result? #59

wahello opened this issue Jun 24, 2021 · 8 comments

Comments

@wahello
Copy link

wahello commented Jun 24, 2021

How to get success result?

@apenella
Copy link
Owner

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
Copy link
Author

wahello commented Jun 25, 2021

@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
Copy link
Owner

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
Copy link
Author

wahello commented Jun 28, 2021

@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
Copy link
Author

wahello commented Jun 28, 2021

I got it.

@cyberchao
Copy link

@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
Copy link
Owner

apenella commented Jul 1, 2021

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
Copy link
Author

wahello commented Jul 4, 2021

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

@wahello wahello closed this as completed Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants