# Issue with curl command running with shell module

**URL:** <https://forum.ansible.com/t/issue-with-curl-command-running-with-shell-module/32160>\
**Category:** Ansible Project\
**Created:** [February 6, 2020, 4:09pm UTC](https://forum.ansible.com/t/issue-with-curl-command-running-with-shell-module/32160 "2020-02-06T16:09:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawan\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@Pawan\_Kumar1](https://forum.ansible.com/u/Pawan_Kumar1)\
**Post date:** [February 6, 2020, 4:09pm UTC](https://forum.ansible.com/t/issue-with-curl-command-running-with-shell-module/32160/1 "2020-02-06T16:09:15Z")

</div>

Hi Team,

Curl command is working fine on command line shell ,but when running the same command using Ansible shell module it’s throwing error .  
The exact issue coming when i am using curl command with multiple parameters (example -i /opt/hosts proxy ) .

Here is my playbook

- name: list for idp  
shell: 'curl -s [http://localhost:8095/proxy/healthcheck](http://localhost:8095/proxy/healthcheck) -i /opt/hosts proxy ’  
register: idp\_out

- debug:  
msg: “{{idp\_out}}”

Output —

fatal: [localhost]: FAILED! =\> {“changed”: true, “cmd”: “curl -s [http://localhost:8095/proxy/healthcheck](http://localhost:8095/proxy/healthcheck) -i /opt/hosts”, “delta”: “0:00:00.016367”, “end”: “2020-02-06 08:00:08.153617”, “msg”: “non-zero return code”, “rc”: 3, “start”: “2020-02-06 08:00:08.137250”, “stderr”: “”, “stderr\_lines”: , “stdout”: "HTTP/1.1 200 OK\r\nDate: Thu, 06 Feb 2020 16:00:08 GMT\r\nContent-Type: application/json\r\nContent-Length: 159\r\n\r\n{"package":"PROXY"

While running the same curl command on linux shell , it’s working fine.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 6, 2020, 10:49pm UTC](https://forum.ansible.com/t/issue-with-curl-command-running-with-shell-module/32160/2 "2020-02-06T22:49:14Z")

</div>

Hi Pawan

You state: "Curl command is working fine on command line shell".  
But in fact, it is not working fine, because it exits with error code  
3, which (according to  
[https://curl.haxx.se/libcurl/c/libcurl-errors.html](https://curl.haxx.se/libcurl/c/libcurl-errors.html)) means "The URL was  
not properly formatted."  
You would have seen that if you didn't suppress the output with the  
"-s" (silent) switch.  
Running the same command from ansible shell will give exactly the same  
result, but ansible is more vocal about non-zero exit codes and hence  
will complain.

Remove the "-s" switch and try to manually tweak the curl command so  
that it yields something useful (preferably something that cleanly  
exits).  
Once that works, it will also work in ansible shell/command.

Dick
