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

AnsibleAdhocCmd return error when args has spaces #90

Closed
ylxxwx opened this issue Feb 11, 2022 · 5 comments · Fixed by #91
Closed

AnsibleAdhocCmd return error when args has spaces #90

ylxxwx opened this issue Feb 11, 2022 · 5 comments · Fixed by #91

Comments

@ylxxwx
Copy link

ylxxwx commented Feb 11, 2022

When I use AnsibleAdhocCmd w/ Args('ping x.x.x.x -c 10'), I see this error. This command works in shell. The root cause is there are spaces in teh args. Any solution?

*errors.Error(&errors.Error{context:"(DefaultExecute::Execute)", message:"Error during command execution: ansible-playbook error: one or more host failed\n\nCommand executed: /usr/bin/ansible all --args 'ping x.x.x.x -c 10' --inventory x.x.x.x, --module-name command --private-key ~/.ssh/gpc_rack_id_rsa\n\nexit status 2", wrappedErrors:[]error(nil)})

@apenella
Copy link
Owner

hi! @ylxxwx
Thanks for rising that issue.
Let me check it.

btw, does it also fails if you execute the command that is show on the error message?

@ylxxwx
Copy link
Author

ylxxwx commented Feb 13, 2022 via email

@apenella
Copy link
Owner

hi @ylxxwx
Can you take a look at command-module-ansibleadhoc example?

I made it run on my system:

❯ go run command-module-ansibleadhoc.go 
Command:  ansible all  --args 'ping 127.0.0.1 -c 2' --inventory  127.0.0.1, --module-name command  --connection local
127.0.0.1 | CHANGED | rc=0 | (stdout) PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.026 ms\n64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.048 ms\n\n--- 127.0.0.1 ping statistics ---\n2 packets transmitted, 2 received, 0% packet loss, time 1001ms\nrtt min/avg/max/mdev = 0.026/0.037/0.048/0.011 ms

It also worked out on a remote server, using ssh connection:

❯ go run command-module-ansibleadhoc.go 
Command:  ansible all  --args 'ping 127.0.0.1 -c 2' --inventory  <IP>, --module-name command 
<IP> | CHANGED | rc=0 | (stdout) PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.017 ms\n64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.021 ms\n\n--- 127.0.0.1 ping statistics ---\n2 packets transmitted, 2 received, 0% packet loss, time 999ms\nrtt min/avg/max/mdev = 0.017/0.019/0.021/0.002 ms

As I could see on #91 , I did not change anything that should solves it, I just quoted the Args value on AnsibleAdhocCmd's String method, which is a cosmetic update.

Let me know, if it helps you.

@ylxxwx
Copy link
Author

ylxxwx commented Feb 16, 2022

It works. thaniks.

@apenella
Copy link
Owner

@ylxxwx just to let you know, I decided to prepare the release v1.1.6 which will have that changes.
Thank you very much!

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

Successfully merging a pull request may close this issue.

2 participants