URI Module fails POST but CURL succeds as shell

I am getting a connection refused socket error :111 when using get_uri module for POST of a zip file to a url . If i use curl command on shell the task runs without error. How can i fix this issue?

What does it show you when you run it in verbose mode?

Hello, this is the error I get , when i run it in verbose mode.

TASK: [Curl to post to oabc] *******************************************
<10.1.3.163> ESTABLISH CONNECTION FOR USER: ubuntu
<10.1.3.163> REMOTE_MODULE uri url=‘http://localhost/api/v1.0/abcd?abcdZipFile=abcd_v3.0_20150701.ZIP
<10.1.3.163> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/vagrant/ahafasfhsalf_Dev.pem” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && echo $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188’
<10.1.3.163> PUT /tmp/tmpGByUla TO /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri
<10.1.3.163> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/vagrant/ahafasfhsalf_Dev.pem” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=szyrygobamhtrmdhebttkjwsmjgkyuhc] password: " -u root /bin/bash -c '”’“‘echo BECOME-SUCCESS-szyrygobamhtrmdhebttkjwsmjgkyuhc; LANG=C LC_CTYPE=C /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/ >/dev/null 2>&1’”‘"’’
failed: [10.1.3.163] => (item=abcd_v3.0_Monthly_Master_20150701.ZIP) => {“failed”: true, “item”: “abcd_v3.0__20150701.ZIP”}
msg: Socket error: [Errno 111] Connection refused to http://localhost/api/v1.0/abcd?abcdZipFile=abcd_v3.0__20150701.ZIP
…ignoring

where is the api running? can you show the curl command that succeeds?
where do you run it from?

The playbook below works with CURL in SHELL but not URI

The API is running on 10.1.3.163

It looks like you’re missing the port (9004) in the URI call. Which would make sense because it’s getting a “connection refused” socket level error.

I added the port and tested again. here is the error I get.

Getting closer. 500 is an internal server error. Do you have access to the server logs? Also, run the playbook with --verbose and set return_content=yes on the task.

I’d also wrap the url in doublequotes. I’m guess the url string is getting messed up somehow.

Status code 500 is an internal server error which means the application you’re talking had a problem. Might check the logs for the application to see if it reported why it couldn’t handle the request.

I also note that the filename that the uri module is trying to POST is different from the filename in your curl. That might be a clue as well.

-Toshio