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
875 stars 142 forks source link

how to get error during command execution? #63

Closed aohan0503 closed 3 years ago

aohan0503 commented 3 years ago

like this image

apenella commented 3 years ago

Hi @aohan0503 When you use DefaultExecutor already shows the errors

I forced an ansible parser error on signals-and-cancellation-ansibleplaybook example and that is the result:

go-ansible/examples/signals-and-cancellation-ansibleplaybook❯ go run signals-and-cancellation-ansibleplaybook.go
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  did not find expected '-' indicator

The error appears to be in '/home/aleix/projects/aleix.penella/go-ansible/examples/signals-and-cancellation-ansibleplaybook/site.yml': line 7, column 6, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    - name: signals-and-cancellation-ansibleplaybook
     debug:
     ^ here
Error during command execution: ansible-playbook error: parser error

Command executed: /home/aleix/.local/bin/ansible-playbook --inventory 127.0.0.1, --connection local --user aleix site.yml

Could you share some code snippets If you need more help?

Thanks!

apenella commented 3 years ago

hi @aohan0503! There is any update about your issue?

Thanks!

aohan0503 commented 3 years ago

hi @apenella I want to get the stderr when ansible is executed ,errors like parsing errors。 Get stderr through go-ansible

aohan0503 commented 3 years ago

Use execute.WithWriteError() method to get

Thanks!

apenella commented 3 years ago

Hi @aohan0503! I understand that you figured out how to solve it. Do you need anything else? Would you mind If I am closing that issue?

aohan0503 commented 3 years ago

@apenella This issue can now be clos