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 can I run the example "ansibleplaybook-walk-through-json-output" #114

Closed Yang-yyf closed 2 years ago

Yang-yyf commented 2 years ago

When I run the example ansibleplaybook-walk-through-json-output.go, I met this err: ERROR! Invalid callback for stdout specified: json Error during command execution: ansible-playbook error: general error

What should I do?

apenella commented 2 years ago

HI @Yang-yyf Thanks for your message.

I executed the example as it comes in the repository, and it works for me

❯ go run ansibleplaybook-walk-through-json-output.go
[127.0.0.1] that is just an example
[127.0.0.1] that is another example

I think that I would need more details, in order to help you. Could you provide me a snippet from the output? Are you running the example as it is?

I tested it using the go-ansible's master branch, the ansible-core's version that I am using is 2.13.6 and the ansible version is 6.6.0.

❯ ansible --version
ansible [core 2.13.6]
  config file = ***
  configured module search path = ***
  ansible python module location = ***
  ansible collection location = ***
  executable location = ***
  python version = 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True
Yang-yyf commented 2 years ago

HI @Yang-yyf Thanks for your message.

I executed the example as it comes in the repository, and it works for me

❯ go run ansibleplaybook-walk-through-json-output.go
[127.0.0.1] that is just an example
[127.0.0.1] that is another example

I think that I would need more details, in order to help you. Could you provide me a snippet from the output? Are you running the example as it is?

I tested it using the go-ansible's master branch, the ansible-core's version that I am using is 2.13.6 and the ansible version is 6.6.0.

❯ ansible --version
ansible [core 2.13.6]
  config file = ***
  configured module search path = ***
  ansible python module location = ***
  ansible collection location = ***
  executable location = ***
  python version = 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True

I do run the command like go run ansibleplaybook-walk-through-json-output.go, and I got this : ERROR! Invalid callback for stdout specified: json Error during command execution: ansible-playbook error: general error

I check the version of my ansible,It seems like this: ansible [core 2.15.0.dev0] config file = None configured module search path = ['/Users/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /opt/homebrew/lib/python3.10/site-packages/ansible_core-2.15.0.dev0-py3.10.egg/ansible ansible collection location = /Users/admin/.ansible/collections:/usr/share/ansible/collections executable location = /opt/homebrew/bin/ansible python version = 3.10.7 (main, Sep 14 2022, 22:38:23) [Clang 14.0.0 (clang-1400.0.29.102)] (/opt/homebrew/opt/python@3.10/bin/python3.10) jinja version = 3.1.2 libyaml = True

apenella commented 2 years ago

Hi! Since go-ansible is just an ansible wrapper to execute it through Golang, would you mind executing it directly with Ansible?

❯ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook -i 127.0.0.1, -c local site1.yml site2.yml

I saw that you are using ansible-core 2.15.0.dev0, which is not a stable release and I don't know how it could influence the results you received.

Yang-yyf commented 2 years ago

Hi, Thanks for your help. It seems that my ansible-core was not a stable release version, because when I run the command directly, ansible returns me the same error. I will change ansible's version. Thank you!

apenella commented 2 years ago

Good to know that we figured out why it does not work! Thank you! I am going to close the issue!

prakasa1904 commented 1 year ago

Hi, sorry to add issue here. I have some problem here but it only happen in docker Ubuntu 22.04 somehow. With detail ansible below:

ansible [core 2.13.6]
  config file = ***
  configured module search path = ['***', '***']
  ansible python module location = /root/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/.local/bin/ansible
  python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True

But it works when I running it in the docker host MacOS with ansible detail below. Can you give me advice about this issue @apenella . Thanks!

ansible [core 2.13.6]
  config file = ***
  configured module search path = ['***', '***']
  ansible python module location = /opt/homebrew/Cellar/ansible/6.6.0/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = ***
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.0 (main, Oct 25 2022, 13:57:33) [Clang 14.0.0 (clang-1400.0.29.202)]
  jinja version = 3.1.2
  libyaml = True

SOLVED - Forget it, if you guys found same issue please install missing dependency when using docker as ansible executor.